Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re^3: passing arrays to subroutines

by tlm (Prior)
on Mar 16, 2005 at 14:26 UTC ( #439951=note: print w/replies, xml ) Need Help??

in reply to Re^2: passing arrays to subroutines
in thread passing arrays to subroutines

Just to expand on this point for the OP's benefit, consider:

use strict; use Dumpvalue; my $dumper = Dumpvalue->new(); my @a = (3, 1, 4, 1); my @b = (5, 9); my @c = (2, 6, 5); sub ex1 { map 10*$_, @_; } $dumper->dumpValue([ex1(@a)]); print "\n"; # array refs sub ex2 { map scalar @$_, @_; } $dumper->dumpValue([ex2(\@a, \@b, \@c)]); print "\n"; # implicit array refs through prototypes sub ex3 (\@\@\@) { map scalar @$_, @_; } $dumper->dumpValue([ex3(@a, @b, @c)]); print "\n"; __END__ 0 30 1 10 2 40 3 10 0 4 1 2 2 3 0 4 1 2 2 3
Note that the bodies of ex2 and ex3 are identical. IMO, however, ex2 is superior, because it can take as arguments any number of array refs, whereas ex3 must take exactly three arrays as arguments.

Follow-up question: is there any way to define a sub that takes as input one or more arrays?

the lowliest monk

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://439951]
[Corion]: Mhhmmm - https://sod.pixlab .io/ looks really interesting for embedding with Perl (XS), but they don't have any kind of free model available and the cheapest pretrained model costs EUR 40 :-(

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (4)
As of 2018-06-18 10:40 GMT
Find Nodes?
    Voting Booth?
    Should cpanminus be part of the standard Perl release?

    Results (109 votes). Check out past polls.