#!/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.


In reply to Re: Hashes with multiple values? by jwkrahn
in thread Hashes with multiple values? by MyaEsp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.