in reply to Are prototypes evil?
Now, let's see a sub where prototypes are very helpful:
So, to do a hyper-add on two lists with that, "dmap { $a + $b } @foo, @bar". Without the prototype, that would have to have been written as the uglier "dmap sub { $a + $b }, \@foo, @bar"sub dmap (&\@@) { my $cl = shift; my $list1 = shift; my $list2 = \@_; my @results; for my $i(0..$#$list1) { local $a = $list1->[$i]; local $b = $list2->[$i]; push @results, &$cl; } return @results; }
Update: Changed $#list1 to $#$list1. Thanks sauoq.
--MrNobo1024
s]]HrLfbfe|EbBibmv]e|s}w}ciZx^RYhL}e^print
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Re: Are prototypes evil?
by sauoq (Abbot) on Sep 03, 2002 at 20:47 UTC |