Scott Pham wrote:
> I've been thinking about this and not sure how to approach this
> problem. Say I want to create an array of 4 array references, thats
> easy since I know that there will be 4 array references, how would I
> do this dynamically? Say if one I only needed 2 references and
> another I need 10 array references, is there a way to do this in
> perl?     

#!/usr/bin/perl -w
use warnings;
use strict;

my @array;
my $num_child_arrays = 10;

for (my $count = 0; $count < $num_child_arrays; $count++) {
    my $array_ref = [ ];
    push (@array,$array_ref);
}



Could probably be done in a shorter format as well...

push (@array,[]) for (1..$num_child_arrays);


For more info:

perldoc -f push


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to