Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
Instead of a filter, you might want to change every item in a
list. For example, suppose you have a list of numbers that should be
formatted as “money numbers” for output, as with the subroutine &big_money from Chapter 13. You don’t want to modify the original
data; you need a modified copy of the list just for output. Here’s one
way to do that:
my @data = (4.75, 1.5, 2, 1234, 6.9456, 12345678.9, 29.95);
my @formatted_data;
foreach (@data) {
push @formatted_data, &big_money($_);
}
That looks similar in form to the example code used at the
beginning of the previous section on grep, doesn’t it? So it may not surprise you
that the replacement code resembles the first grep example: