Perl syntax

Hi,
Anyone can help me? I want to the AND condition in my perl script which as below:

if number > 1 and allow_yn = 'Y'
then
 ......

How should I write in perl, what is the syntax?

thanks,
Chewlf
chewlfAsked:
Who is Participating?
 
BigJoe1008Commented:

use strict;

my $number = 4324;
my $allow_yn = 'y';

if(($number > 1) && (uc($allow_yn) eq 'Y')){
     do my stuff here
}


This is how it would look.  Always "use strict;".  Besure to put a $ infront of your variables (so they don't become constants) and use my to declare you variables in the scope of the function and/or script. The uc function will make sure it is uppercase.  
0
 
DVBCommented:
if (($number = 1) and (allow_yn eq "Y")) {
&stuff();
}
else {
die "Stuff not allowed";
}
0
 
chewlfAuthor Commented:
Hi DVB,
It seems like doesn't work. I want to meet both conditions in order to run the next statement. Can I use && here?

Thanks,
Chewlf
0
 
andreifCommented:
I suggest, you missed $ before "allow_yn"
Another error is using "=" instead of "==".

Final code is

if (($number == 1) and ($allow_yn eq "Y")) {
&stuff();
}
else {
die "Stuff not allowed";
}

you can use "and" as well as "&&"
0
 
andreifCommented:
Sorry, $number == 1 should read as $number > 1, of course
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.