"..does not give me the entire elements in the array..it jus gives me the last hash in the array.."
Well, that's because you clobber the %alarm_details hash on each iteration.
Personally, I think you could do away with the @alarm_details array altogether and just use a HoH. Also, I'd go for a split rather than using a regexp, and split the lines directly into named variables. Something like this (untested):
my %alarm_details; my @files = </TELECOM_PROJ_MAIN/sas/tmp/t*>; foreach my $file (@files) { open LOG, "<", $path or die "Can't open $file:$!\n"; $alarm_details{filepath} = $file; while (<LOG>) { chomp; my ($key, $value) = split /=/, $_; $alarm_details{filepath}{$key} = $value if ($key); } close LOG; }
Also note that I changed @paths to @files, which seems to be more appropriate. And, the 3 argument form of open is better practise, as is checking $! upon failure.
One more thing to note is that the above code would throw "uninitialised value" warnings on any lines that had no data to the right-side of the equals (=). But you could get rid of that by explictitly checking for both $key and $value on each iteration.
Hope this helps,
Darren :)
In reply to Re: reuse hashes in another method
by McDarren
in thread reuse hashes in another method
by perumal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |