Pages

Sunday, January 10, 2010

Perl Script to Add or Remove Colons from WWNs

Some days it seems like a large portion of my job is pasting WWNs from Cisco MDS switches into SYMCLI (and back).  MDS switches require the WWNs to have colons in them, SYMCLI requires no colons.

I wrote a quick and dirty script in Perl (with a little help from Aaron on the backreference) to add or remove colons from what is currently on the clipboard. 

Requires Microsoft Windows and ActiveState Perl.
use Win32::Clipboard;
$CLIP = Win32::Clipboard();
$x = $CLIP->Get();
if ($x =~ m|:|) {
    $x =~ s|:||g;
}
else {
    $x =~ s|(.{2})|$1:|g;
    $x =~ s|:$||;
}
$CLIP->Set($x);

No comments: