Solved

Perl syntax

Posted on 2002-06-03
5
233 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

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
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…
Six Sigma Control Plans

707 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