erik has asked for the wisdom of the Perl Monks concerning the following question:

Hello brothers in Perl-ism,

I have been googling about element-wise operations on arrays and all that I found was that it's a subject of debate if/how it should be introduced in Perl 6.

Do you know better? Is it available in Perl 5.8.8 directly (built-in) or indirectly (module or snippet)? Supposing that I code it myself, do you recommend me to just do it as a set of functions accepting arrays/scalars as arguments or as an overload of operators?

Thanks in advance for your suggestions!

Erik

Replies are listed 'Best First'.
Re: Element-wise operations
by moritz (Cardinal) on Feb 27, 2008 at 13:41 UTC
    PDL implements mathematic operations on arrays.

    Apart from that, it all depends.

    # calling a method on each item: #Perl 6: @list>>.method; #Perl 5: map { $_->method } @list; # summing all elements: #Perl 6: my $sum = [+] @numbers; # Perl 5: use List::Util qw(sum); my $sum = sum @numbers; # adding two vectors item by item: # Perl 6: @v1 >>+<< @v2; # Perl 5: Needs PDL or overloading for neat syntax.