in reply to Hashes with multiple values?

#!/usr/bin/perl
use strict;

And don't forget:

use warnings;

my $value;

You don't need this variable in file scope

my $infile = "student.data";
my @lines = <INPUT>;

You haven't opened the INPUT filehandle yet so that statement makes no sense.

if(!open(INPUT, "<$infile")){
   print "Can't open file $infile\n";
   die;

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?

}
while(<INPUT){

You are missing the closing  > delimiter.

   chomp;
   my %hash = ();

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}/;
    push @{$config{$key}}, $value;
}

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
    Please use code tags <c> code goes here </c> or <code> code goes here </code>

      I did use code tags.    But thanks for asking.    :-)

        Hmm, a bug Download Code returns # no code to download

        Your use of font colors is not theme-safe