On Sat, Mar 22, 2008 at 1:02 AM, Richard Lee <[EMAIL PROTECTED]> wrote:
> let's say I have
>
> @someting = qw/1 2 3 4/;
>
> @something2 = qw/110 11 12/;
>
> @something3 = qw/20 30 40 50/;
>
> and I get the name of array from regular expression match something like
> this from some other file
>
> $_ =~ /^(\S+) \s\s$/;
>
> so, now $1 is either something or something2 or something3,
>
> and if I wanted to do
>
> something like
>
> @bigarray{ @something } = split
>
> how can use $1 to put it inside?
>
> I was thinking something like
>
> @bigarray{ @($1) } = split ??
> but doesn't work..
> can someone advice?
snip
I am not sure what you are trying to achieve with
"@[EMAIL PROTECTED] = split", it is a hash slice, but the values in
@something don't look like keys, so I assume you didn't mean for it to
be one. Here is how you can get an array dynamically:
#!/usr/bin/perl
use strict;
use warnings;
my %arrays = (
something => [qw<1 2 3 4>],
something2 => [qw<110 11 12>],
something3 => [qw<20 30 40 50>]
);
while (<>) {
if (my ($key) = /^(\S+) \s\s$/) {
if (exists $arrays{$key}) {
print join(",", @{$arrays{$key}}), "\n";
} else {
print "no array named $key\n";
}
} else {
print "input was in the wrong format\n";
}
}
--
Chas. Owens
wonkden.net
The most important skill a programmer can have is the ability to read.
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/