Beefy Boxes and Bandwidth Generously Provided by pair Networks kudra
Don't ask to ask, just ask
 
PerlMonks  

Re: How to declare arrays and scalars together?

by cheekuperl (Monk)
on Jun 18, 2012 at 05:18 UTC ( #976752=note: print w/ replies, xml ) Need Help??


in reply to How to declare arrays and scalars together?

As such, nothing looks/IS wrong in your code. It's just that it does not work the way you are thinking it would.

my (@arr1, @arr2, $var, @arr3) = ( (1,2),(11,22),"0", () ); print "\n[@arr1]"; print "\nvar is $var";
RHS of first line is flattened into a single list and copied in its entirety into @arr1.
All other elements in LHS of first line are empty. Remember why you can not pass multiple arrays to a subroutine?


Comment on Re: How to declare arrays and scalars together?
Download Code
Re^2: How to declare arrays and scalars together?
by 2teez (Chaplain) on Jun 18, 2012 at 05:36 UTC

    "Remember why you can not pass multiple arrays to a subroutine?"

    except, one uses reference like so:

    my $arr1_ref = [ 1, 2, 3 ]; my $arr2_ref = [ 10, 9, 8, 7 ]; load_arr( $arr1_ref, $arr2_ref ); ## load multiple array references sub load_arr { my ( $arr1_def, $arr2_def ) = @_; print join "\n", @{$arr1_def}, @{$arr2_def}; return; }

      You're passing array references there, not arrays.

        That is my point. It is possible to pass multiple arrays, using array reference.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (11)
As of 2013-05-18 14:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best material for plates (tableware) is:









    Results (392 votes), past polls