Richard Lee wrote:
say I have file
--file--
something3 one two three and so on
something two two two so one
something one two three
so on and so forth
program
@something = qw/val1 val2 val3 and so forth/;
@something2 = qw/vala valb valb and so forth/;
@something3 = qw/valZ valZ1 valZ2 so forth/;
while ( <file>) {
/^(\S+) .+$/; #find out what
the first word of first line is, in this case-------> something3 ---->
line is something3 one two three.....
@[EMAIL PROTECTED] = split # use the $1 value from
above and use that name to find the appropriate array name that u should
be using for key
# so it
will assign
valZ => something3
valZ1 => one
valZ2 => two
Is that clear?
No, it's not very clear.
C:\home>type test.pl
use Data::Dumper;
my %HoA = (
something => [ qw/val1 val2 val3 and so forth/ ],
something2 => [ qw/vala valb valc and so forth/ ],
something3 => [ qw/valZ valZ1 valZ2 so forth/ ],
);
my %HoH;
while ( <DATA> ) {
/^(\S+)/;
@{ $HoH{$1} }{ @{ $HoA{$1} } } = split;
}
print Dumper \%HoH;
__DATA__
something3 one two three etc
something2 two three and so on
something one two three four five
C:\home>perl test.pl
$VAR1 = {
'something3' => {
'so' => 'three',
'valZ2' => 'two',
'forth' => 'etc',
'valZ1' => 'one',
'valZ' => 'something3'
},
'something2' => {
'so' => 'so',
'valb' => 'two',
'forth' => 'on',
'valc' => 'three',
'vala' => 'something2',
'and' => 'and'
},
'something' => {
'so' => 'four',
'forth' => 'five',
'val2' => 'one',
'val1' => 'something',
'val3' => 'two',
'and' => 'three'
}
};
C:\home>
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/