Solved

Perl syntax

Posted on 2002-06-03
5
231 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Email validation in proper way is  very important validation required in any web pages. This code is self explainable except that Regular Expression which I used for pattern matching. I originally published as a thread on my website : http://www…
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…
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…

756 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