|
In a message dated 3/28/2005 9:18:20 P.M. Eastern Standard Time,
[EMAIL PROTECTED] writes:
> Daniel Wilson wrote:
> > > Hello Perl World! > > > > I need a little help.. > > > > I currently have the followings (hard coded) definition in one of my > > perl program that I am currently upgrading. > > > > # A five by five Hash Array > > my @GlobalArrayRef; > > $GlobalArrayRef[0] = [ [0,0,0,0,0], [0,0,0,0,0], [0,0,0,0,0], > > [0,0,0,0,0], [0,0,0,0,0] ]; > > > > I need to change this to where I can set the hash array size dynamically > > (during runtime) and not hard coded to a specific size. Any Ideas? > > Just do a double foreach loop to create dynamically all the default > elements of the arrays. > > my @GlobalArray; using (0 .. 5) yields six array elements. use (0 .. 4) for 5
elements as in original example.
> foreach my $outer (0 .. 5) { > foreach my $inner (0 .. 5) { > $GlobalArray[$outer][$inner] = 0; > } > } > > Adjust to suit - I used a straight doubly indexed array. > > -- > ,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED] to completely recreate the effect of the original code, use
$GlobalArrayRef[0] = [EMAIL PROTECTED];
foreach my $outer (0 .. 5) { # example of
access
foreach my $inner (0 .. 5) { print $GlobalArrayRef[0]->[$outer][$inner], "\n"; } } for more info on references and nested data structures, see the activestate
doc pages perlref, perlreftut, perllol. hth -- bill walters
|
_______________________________________________ ActivePerl mailing list [email protected] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
