Solved

mutiple commands from an if statement on one line...

Posted on 2002-05-30
4
167 Views
Last Modified: 2012-05-04
My question is quite simple suppose i have multiple commands to do, ie

print "success";
$counter++;

can i do these on a line if statement.

ie
print "success" && $counter if (condition is true);

many thanks
Peewee
0
Comment
Question by:Peewee
4 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 50 total points
ID: 7044872
Code below should do that.
Don't understand why you would want to though, it's not very readable. Probably better to use separate statements.

#!/usr/bin/perl

$test=1;
(print "success"),(($test >= 1) ? $counter++ : 0) , (print " counter=$counter");

0
 
LVL 1

Expert Comment

by:pagemastah
ID: 7044881
you may use the DO-WHILE statement... for example:

do
{
print "success\n";
$counter++;
}
while ($counter < 10);

##### this will print 'success' and increment the value of $counter and then stops if the value of $counter is not less than 10 anymore.

i hope this one helps...

0
 
LVL 5

Author Comment

by:Peewee
ID: 7047056
rj2,

here's what i used:
#!/usr/bin/perl

print "start\n";
$test=1;
print "first success\n"), (print "second success\n") if $test;
print "end\n";


many thanks
Peewee
0
 
LVL 84

Expert Comment

by:ozo
ID: 7047888
why not

print "first success\n","second success\n" if $test;
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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…
A year or so back I was asked to have a play with MongoDB; within half an hour I had downloaded (http://www.mongodb.org/downloads),  installed and started the daemon, and had a console window open. After an hour or two of playing at the command …
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

920 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

13 Experts available now in Live!

Get 1:1 Help Now