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

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.