Solved

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

Posted on 2002-05-30
4
155 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
why not

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

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

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.…
In the distant past (last year) I hacked together a little toy that would allow a couple of Manager types to query, preview, and extract data from a number of MongoDB instances, to their tool of choice: Excel (http://dilbert.com/strips/comic/2007-08…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

763 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

6 Experts available now in Live!

Get 1:1 Help Now