Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine

Re: Multiple commands separated by commas

by Marshall (Abbot)
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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://923961]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (6)
As of 2018-05-27 12:16 GMT
Find Nodes?
    Voting Booth?