Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Array of array

by nagalenoj (Friar)
on Jun 04, 2009 at 07:44 UTC ( #768330=note: print w/replies, xml ) Need Help??

in reply to Array of array

Dear monk,

We cant separate as what you have asked. Since, it has been given in the perldoc for push that, this function is just appending a list to an array.

But, it is possible to push a reference to the array and get back a particular list of elements. like below.,

push @mainarr,\@arr1; print Dumper @mainarr->[1];

UPDATE: Similar answer has been given above when I am typing this, sorry for the repetition

Replies are listed 'Best First'.
Re^2: Array of array
by wfsp (Abbot) on Jun 04, 2009 at 13:00 UTC
    ...sorry for the repetition.
    There's no need to be sorry. I like to see a few versions of a solution. I often pick up handy techniques comparing different approaches.

    A minor nit though, your snippet won't compile throws a warning under strict and warnings. This is a bit better.

    #!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @arr1 = qw{one two three}; my @arr2 = qw{four five six}; my @mainarr; push @mainarr, \@arr1, \@arr2; #print Dumper @mainarr->[1]; # <- line 12 #Using an array as a reference is deprecated at C:\perm\ line 1 +2. #C:\perm\ syntax OK print Dumper $mainarr[1]; __DATA__ $VAR1 = [ 'four', 'five', 'six' ];

    My motto: "Test it _before_ you post it." :-)

    update: it does compile ("syntax OK") but it throws a warning

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://768330]
[Corion]: 1nickt: Would be great, especially for naming parameters in @_.
[Corion]: When you pass an arrayref, you get to treat it like a local array. But then, I'm cautious with the experimental features, because just when I thought function signatures were a set thing, there is a proposal to use sub [ $foo, $bar ] { ... } to ...
[Corion]: ... declare the parameters, instead of the more common sub ($foo, $bar) { ... }

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2017-11-17 20:42 GMT
Find Nodes?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:

    Results (272 votes). Check out past polls.