in reply to Hashes with multiple values?
And don't forget:
use warnings;You don't need this variable in file scope
my $infile = "student.data";You haven't opened the INPUT filehandle yet so that statement makes no sense.
if(!open(INPUT, "<$infile")){You should include the $! variable in your error statement so you know why it failed. Why not just let die print out the error message?
}You are missing the closing > delimiter.
chomp;Because %hash is declared as a lexical variable inside the while loop it is only visible inside the while loop.
my($key, $value) = split /[\d]{9}\s+[a-z|A-Z]{1,9}\s+[a-z|A-Z]{1,9}\s+[A-Z]{2}\s+[A-Z]{2}/;split removes whatever the pattern matches and returns a list of everything that didn't match so it looks like nothing will be returned. Your character class [a-z|A-Z] includes the '|' character but it doesn't look like your data contains that character. What you probably want is something like:
while ( <INPUT> ) {
my ( $key, @values ) = split ' ', $_, -1;
push @{ $config{ $key } }, @values;
}
@studentList = @{$config{"studentList"}};
It doesn't appear that your data has a "studentList" key, it looks like all the keys are nine digit numbers.
@sortedList1 = sort(keys, %hash);You can't use %hash here because it is lexically scoped to the while loop.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Hashes with multiple values?
by Anonymous Monk on Mar 31, 2008 at 08:34 UTC | |
by jwkrahn (Abbot) on Mar 31, 2008 at 08:40 UTC | |
by Anonymous Monk on Mar 31, 2008 at 11:22 UTC |