Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

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

Posted on 2002-05-30
4
Medium Priority
?
195 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
[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
4 Comments
 
LVL 10

Accepted Solution

by:
rj2 earned 200 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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
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

705 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