
liton79
Novice
Sep 25, 2013, 8:22 AM
Post #1 of 4
(2308 views)
|
Hash key value is not returning properly
|
Can't Post
|
|
Hi Guru's, I am new in Perl language and trying to write a simple perl program using hash table which will read a text file 'month.txt'. The program will search for a word (example: December) and should return that particular line that matches the word. If the line is repeated in the file numerous time it should return all the matching lines. Below is my program and but I am not able to figured out why it is only returning the output 'ARRAY(0x5063d0)' instead of the lines that contains word December. Please help. Also, would appreciate if you could explain to me the code on your reply which will help me to understand the code. Thank you in advance. 1 #!/usr/bin/perl 2 use warnings; 3 use strict; 4 5 my %hash; 6 my $key = ""; 7 open (INFO, "month.txt") or die "couldn't open the input file $!"; 8 while (<INFO>) 9 { 10 chomp; 11 if (/^December/) 12 { 13 push @{$hash{$key}}, $1; 14 print "$hash{$key} \n" 15 } 16 } 17 close (INFO); OUTPUT: ==> ./readfile.pl ARRAY(0x5063d0)
|