I have studied posts at the monastery in an effort to learn to code Perl more professionally. I have created a script to read a flat file that contains TIDs and possible NUMBERs that are associated with the TID. It uses a multidimentionally hash to store values found in a flat file and print them out as they are found however, when I attempt to wait until the flat file is processed to its end and closed, then use a foreach loop to print the hash contents the warning "Use of unitialized value in concatenation (.) or string at ./z line 33." is printed for the sub elements of the hash. Can you help me to understand what is happening to my data between the execution of the while loop and the execution of the foreach loop.
my code
#!/usr/bin/perl -w use strict; # hashes my %Tids=(); # scalars my $Tid=""; # subroutines sub findNumbers; sub findTids; open(IN,"<file"); while(<IN>) { if(/ORIGINATION_ATTEMPT/) { &findTID; print "$Tid,$Tids{\$Tid}{a},$Tids{\$Tid}{b}\n"; } } close(IN); print "============================================\n"; foreach $Tid (keys(%Tids)) { print "$Tid,$Tids{\$Tid}{a},$Tids{\$Tid}{b}\n"; } ## subroutines sub findTID { my $line=(<IN>); if($line =~ /Tid: ([0-9a-f]{8})/) { $Tid = substr($1,3,5); $Tids{$Tid}=$Tid; $Tids{\$Tid}{a}="----------"; $Tids{\$Tid}{b}="----------"; &findNumbers; } } sub findNumbers { my $line=""; while($line !~ /\-{40}/) { $line=<IN>; if($line =~ /FIRST_NUMBER\s+(\d+)\s/) { $Tids{\$Tid}{a}=$1; } if($line =~ /SECOND_NUMBER\s+(\d+)\s/) { $Tids{\$Tid}{b}=$1; } } }
In reply to multidimensional hash value seems to become unitialized by adevans57
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |