Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid

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?

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

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2015-11-30 08:16 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (765 votes), past polls