Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: Multiple commands separated by commas

by Marshall (Prior)
on Sep 03, 2011 at 04:38 UTC ( #923961=note: print w/ replies, xml ) Need Help??


in reply to Multiple commands separated by commas

The comma operator can be complicated.
I would not use the comma operator in this complex of a situation.

If there are multiple parts, put () around the comma parts(eg (part1), (part2,)) and it will parse like you expect.

#!usr/bin/perl -w use strict; for my $i (1..9) { (print "Next"), next if $i == 5; print $i } __END__ Output: 1234Next6789
Another what I think is better coding (don't use the comma if not needed):
#!usr/bin/perl -w use strict; for my $i (1..9) { if ($i == 5) { print "Next"; next; } print $i; } __END__ Output: 1234Next6789
The basic thing with the comma operator, is that what appears in the last part of the comma statement is what matters.


Comment on Re: Multiple commands separated by commas
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://923961]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (8)
As of 2015-07-02 22:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (46 votes), past polls