Hi all,

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


In reply to Beginner question hash&RegEx by Kafkas

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.