perl514 has asked for the wisdom of the Perl Monks concerning the following question:
Respected Monks,
Please let me know if there is a way that I can insert the logical OR or AND operator in an if loop.
Reason to do this is, I have a condition wherein I need to check if a string contains colon ":" or if the string is not equal to 16 characters, the script should exit.
I know I can write if elsif else, but, am trying to find a way if the || operator, or the && operator can be inserted in an if loop so that I can say something like the following. I tried it out, but its not working.
if ($string=~m/:/g || length($string)!=16) { print "Either : already in string on the length is invalid\n"; exit; } else { work on that string }
Please let me know. Kindly note that I am not a trained programmer and though I have some extremely primitive C knowledge, I am a newbie to Perl, so any mistakes/misconceptions on my understanding of the if loop, please pardon me.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to insert || and && in an if loop
by Eliya (Vicar) on Dec 17, 2011 at 19:32 UTC | |
by AnomalousMonk (Archbishop) on Dec 17, 2011 at 22:33 UTC | |
|
Re: How to insert || and && in an if loop
by hbm (Hermit) on Dec 17, 2011 at 19:29 UTC | |
by AnomalousMonk (Archbishop) on Dec 17, 2011 at 21:59 UTC | |
|
Re: How to insert || and && in an if loop
by perl514 (Pilgrim) on Dec 18, 2011 at 06:22 UTC | |
by GrandFather (Saint) on Dec 18, 2011 at 20:56 UTC | |
by i5513 (Pilgrim) on Dec 18, 2011 at 12:17 UTC | |
|
Re: How to insert || and && in an if loop
by perl514 (Pilgrim) on Dec 19, 2011 at 07:10 UTC |