Found in /usr/share/perl/5.34/pod/perlfaq4.pod How do I perform an operation on a series of integers? To call a function on each element in an array, and collect the results, use: my @results = map { my_func($_) } @array; For example: my @triple = map { 3 * $_ } @single; To call a function on each element of an array, but ignore the results: foreach my $iterator (@array) { some_func($iterator); } To call a function on each integer in a (small) range, you can use: my @results = map { some_func($_) } (5 .. 25); but you should be aware that in this form, the ".." operator creates a list of all integers in the range, which can take a lot of memory for large ranges. However, the problem does not occur when using ".." within a "for" loop, because in that case the range operator is optimized to *iterate* over the range, without creating the entire list. So my @results = (); for my $i (5 .. 500_005) { push(@results, some_func($i)); } or even push(@results, some_func($_)) for 5 .. 500_005; will not create an intermediate list of 500,000 integers.
Generated by phpman v4.0 Author: Che Dong Under GNU General Public License
2026-06-16 03:25 @216.73.217.83
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)