Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: How to get two array in subroutine

by CountZero (Bishop)
on Feb 09, 2011 at 13:27 UTC ( [id://887196]=note: print w/replies, xml ) Need Help??


in reply to How to get two array in subroutine

You cannot unless you like jumping through a lot of hoops or using prototypes. Using references is the canonical way of doing this.

If you would try prototypes (and you really do not want to do that unless you know pretty well what you are doing) you can try this:

use Modern::Perl; sub no_ref(\@\@) { my ($first, $second) = @_; say "First: @$first"; say "Second: @$second"; } my @alfa = (1 .. 10); my @beta = ('a' .. 'j'); no_ref @alfa, @beta;
Output:
First: 1 2 3 4 5 6 7 8 9 10 Second: a b c d e f g h i j
It still uses references, but they are kind of hidden. And you cannot call the subroutine with &no_ref!

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: How to get two array in subroutine
by arivu198314 (Sexton) on Feb 09, 2011 at 13:39 UTC
    without reference, we can do by splitting and merging the arrays.
      As I said, by jumping through a lot of hoops. :)

      CountZero

      A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

        hoops are for testes

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://887196]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (8)
As of 2024-04-19 08:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found