in reply to Question on syntax
About your examble: It's a litte confusion what you like to show. In this special, actuall quite special, case print @array; is the common because it calls print only once.
Perl is about having multiple ways to do one thing, so your 2nd and 3rd line differ only in style, not in correctness. Note that the style in the 3rd line would also work for multiple commands while the 2nd line wouldn't.
If you generalise this example to the case that you like to call one function several times with each element of a list/array, then I would code it like this:
function($_) foreach (<list>); # or
function($good_name) foreach my $good_name (<list>);
Also note that AFIK for and foreach do the same with the same arguments, you just should "use for when you mean for and use foreach when you mean foreach".
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Question on syntax
by ikegami (Patriarch) on Apr 23, 2008 at 08:38 UTC | |
by mscharrer (Hermit) on Apr 23, 2008 at 09:09 UTC |