Respencted Monks, Thank you for taking time to reply. I want to try the insertion of || Operator because currently my script looks like this:
#!/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.

Perl Version - (v5.14.2) MSWin32-x64-multi-thread on Windows 7 64 Bit.

In reply to Re: How to insert || and && in an if loop by perl514
in thread How to insert || and && in an if loop by perl514

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.