Solved

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

Posted on 2002-05-30
4
173 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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

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.…
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…
In a recent question (https://www.experts-exchange.com/questions/28997919/Pagination-in-Adobe-Acrobat.html) here at Experts Exchange, a member asked how to add page numbers to a PDF file using Adobe Acrobat XI Pro. This short video Micro Tutorial sh…

776 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