Hey guys, thanks again for all of the help. I believe I have figured out a lot of the silly errors I was making, and have a more general question.
I am using a hash for the same data file as I showed before:
777666555 Smith Tom RM So
111222333 Jones Mary SD Fr
555444333 Johnson Lee IE Sr
I am reading it in from the file, and using split, am extracting the first piece of data (the ID) to be the hash key, and the remainder to be the values. Here is the snippet:
while(my $line2 = <INPUT>){
chomp($line2);
my @splitStudent = split(' ', $line2);
$size = @splitStudent;
my $keys = splitStudent[0];
my $Lname = splitStudent[1];
my $Fname = splitStudent[2];
my $Major = splitStudent[3];
my $Year = splitStudent[4];
}
my @IDSorted = sort(keys(%student));
However, I do not understand how to store the data from the entire file. It seems to me that this code would work only to read in one line. My problem arose when later, I am taking user input to determine if it matches a key...then, if so, outputting each piece of data corresponding to that key. How exactly would I obtain the Fname, Lname, and so on...in order to print?
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.