Solved

Perl syntax

Posted on 2002-06-03
5
226 Views
Last Modified: 2010-03-05
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
0
Comment
Question by:chewlf
5 Comments
 
LVL 3

Expert Comment

by:DVB
ID: 7053089
if (($number = 1) and (allow_yn eq "Y")) {
&stuff();
}
else {
die "Stuff not allowed";
}
0
 

Author Comment

by:chewlf
ID: 7053210
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
 
LVL 6

Expert Comment

by:andreif
ID: 7053344
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
 
LVL 6

Expert Comment

by:andreif
ID: 7053345
Sorry, $number == 1 should read as $number > 1, of course
0
 
LVL 1

Accepted Solution

by:
BigJoe1008 earned 50 total points
ID: 7078391

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

Featured Post

What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

Join & Write a Comment

I have been pestered over the years to produce and distribute regular data extracts, and often the request have explicitly requested the data be emailed as an Excel attachement; specifically Excel, as it appears: CSV files confuse (no Red or Green h…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

743 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now