I am having a very small difficulty in Perl.
I am reading a text file which for some information. While I read the text file, I select some keys from text; as I read further, I wish to save an array of values for the keys.
See for e.g.
Alpha 1
Something: 2132
Something: 2134
Alpha 2
Something: 2132
Something: 2134
I read the file into an array called lines:
my $h;
my $alpha;
for my $line (@lines){
if ($line =~ m/Alpha (\d+)/){
$alpha = $1;
$h->{$alpha} = (); # create empty array for key?
}
elsif ($line =~ m/Something: (\d+)/){
push($h->{$alpha}, $1);
}
}
Apparently, it gives me an error:
Type of arg 1 to push must be array (not hash element) at test.pl line 28, near "$1)"
Execution of test.pl aborted due to compilation errors.
Unable to figure this out.