On Mon, 2002-04-29 at 17:19, [EMAIL PROTECTED] wrote:
> Hi all - should be simple - but I cannot figure it out
> 
> basically i want to name an array with  a subscript ie world0[0] and world1[0]   the 
>0/1 being a variable, i have tried to
>  produce a simple example....
> 
> For any help - thanks..
> ----------------------------------------------------------
> @fred = "one,two,three,four";
> 
> $a=0;
> 
> @array$a=split(/,/, @fred)
> 
> for ($b=0;$b<4;$b++) {
> print @array$a[$b];
> }

Well, the answer to your question is "use eval", but you are better of
using an array of arrayrefs (AKA a LOL or Array of Arrays).

EVAL METHOD
#!/usr/bin/perl -w
use strict;

my @fred = "one,two,three,four";

for my $a (0..3) {
        eval "my \@array$a=split(/,/, \@fred)";
}

for my $b (0..3) {
        eval qq(print \@array$a[\$b], "\\n");
}

ARRAY OF ARRAYREFS METHOD
#!/usr/bin/perl -w
use strict;

my @fred = "one,two,three,four";

my @array;

for my $a (0..3) {
        $array[$a] = [split(/,/, \@fred];
}

for my $b (0..3) {
        print @{$array[$b]}, "\n";
}

-- 
Today is Prickle-Prickle the 46th day of Discord in the YOLD 3168
All Hail Discordia!

Missile Address: 33:48:3.521N  84:23:34.786W


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to