Kafkas has asked for the wisdom of the Perl Monks concerning the following question:
I have a data.txt list with informations about students. Each line with informations about:
name,id_number,faculty,exam day(in form of "yyyy/mm/dd"),address,...
I want to understand how the programm works.Who can tell me, how the hash in line 9 will be created and how it works with $hash{year}(line 13)?
Thanks for any answer
(and excues me for my worse English)
1 #!/usr/bin/perl -w 2 3 my $filename = "data.txt" ; 4 my %hash=(); 5 6 open(FILEHANDLE,"<$filename") || die "Cannot open $filename!"; 7 while(my $line=){ 8 chomp $line; 9 $hash{$1}++ if ($line =~ /.*:(.{4})\/.{2}\/.{2}:.*$/); 10 } 11 close(FILEHANDLE); 12 13 print "In the Year 2002 you checked $hash{ 2002 } exams! \n";
20040315 Edit by Corion: Added code tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Beginner question hash&RegEx
by Abigail-II (Bishop) on Mar 15, 2004 at 11:51 UTC | |
|
Re: Beginner question hash&RegEx
by astroboy (Chaplain) on Mar 15, 2004 at 11:59 UTC | |
|
Re: Beginner question hash&RegEx
by Kafkas (Initiate) on Mar 15, 2004 at 13:00 UTC |