in reply to How to insert || and && in an if loop
#!/usr/bin/perl use warnings; use strict; print "Enter a for lowercase and colons. b to do it the other way around. q to quit "; my $choice = 0; my $wwn = 0; chomp ($choice = <STDIN>); if ($choice eq "a") { until ( $wwn eq "q") { print "Enter the wwn or q to quit: "; chomp ($wwn=<STDIN>); if ($wwn=~m/:/g) { print "WWN already contains :\n"; exit; }#closing for if ($wwn=~m/:/g) elsif (length($wwn)!=16) { print "Invalid WWN Length\n"; exit; }#closing for elsif (length($wwn)!=16) else { my @wwn = unpack ("(a2)*", lc($wwn)); @wwn = join (":", @wwn); print "@wwn\n"; } #closing for lowering case and adding : in wwn. }#closing for until ( $wwn eq "q") }#closing for if choice =a elsif ($choice eq "b") { until ($wwn eq "q") { print "Enter the wwn with : or q to quit: "; chomp ($wwn=<STDIN>); $wwn =~ s/://g; print lc($wwn), "\n"; } #closing for until ($wwn eq "q") }#closing for if choice =b elsif ($choice eq "q") { exit; }#closing for elsif ($choice eq "q")
What the script does is, it takes a 16 character long wwn and if I need it to be in lowercase and a ":" needs to be inserted, it does that. The second option is it removes the ":".
I need this functionality as these strings are WWNs aka World Wide Names that are used in the SAN Connectivity. Sometimes I need them in lowercase with ":" in them and sometimes I need them without ":". When I login to Cisco SAN Switches and search for these, I get them with ":". Other places where I need to put them, they should go without the ":".
My foremost apologies if the indentation is not good/confusing or if there are too many comments. I am newbie and hence still trying to come to terms with the way scripts are written. Please note that I have tried to present the script in the forum in the best possible manner and kindly pardon my mistakes.
Please direct me to pointers or guides where I can read from and improve on this script. If there is any guide or any article that shows how to write scripts in a better way indentation wise etc, kindly let me know. All of you have been very helpful and without your help, I would not be able to enjoy Perl.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How to insert || and && in an if loop
by GrandFather (Saint) on Dec 18, 2011 at 20:56 UTC | |
|
Re^2: How to insert || and && in an if loop
by i5513 (Pilgrim) on Dec 18, 2011 at 12:17 UTC |