in reply to Getting a result from "foreach" block
ormy @results; foreach (@data) { $_ = $_ * 13; push @results, $_; }
You will find the "return" of the loop in @results.my @results; push @results, $_*13 for @data;
The most "perlish" way of doing such a thing of course uses map (as AppleFritter already said]:
my @results = map $_*13, @data;
CountZero
A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James
My blog: Imperial Deltronics
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting a result from "foreach" block
by AnomalousMonk (Archbishop) on Jun 25, 2014 at 18:51 UTC | |
by RonW (Parson) on Jun 26, 2014 at 17:18 UTC | |
by AnomalousMonk (Archbishop) on Jun 26, 2014 at 18:31 UTC |