in reply to Question on syntax

As has been pointed out, the first line is different from the other two - it is printing the entire list at once whilst the other two are printing it one element at a time.

IMHO, as long as its not a one-liner you should do the following:

for my $number ( 1 .. 10 ) { print $number; }

This would allow you/someone else to more easily add more steps to the loop:

for my $number ( 1 .. 10 ) { $number *= $number; print $number, "\n"; }

Hope that helps


Smoothie, smoothie, hundre prosent naturlig!

Replies are listed 'Best First'.
Re^2: Question on syntax
by Porculus (Hermit) on Apr 23, 2008 at 20:41 UTC
    This would allow you/someone else to more easily add more steps to the loop

    The "easy to add another line" thing is a bit of a red herring; any decent editor can convert a postfix for to a block for with a single keypress.

    The real reason to prefer block for is that it allows you to bind the loop variable to something other than $_ (eg your $number), which often makes for more readable code.