One basic problem is this: $Tids{$Tid}=$Tid; assigns a scalar to $Tids{$Tid} which is not what you want. The value of $Tids{$Tid} will wind up being a hash reference - not a scalar. I made some changes to your code below. Essentially take that line out! I can see from the error messages why you would have been driven to try \$Tid as a key, but that is not the right approach.

I would not use $Tid as a global. Pass it around when you need it. Check the value of the open of the file named "file" to make sure that it worked. Instead of using "a" and "b", why not use something more descriptive like the text that was in the file, ie FIRST_NUMBER, etc?

I could make some other comments, but the most important part here is to understand the multi-dimensional hash.

#!/usr/bin/perl -w use strict; use Data::Dumper; # hashes my %Tids=(); #open(IN,"<file") or die "unable to open file"; while(<DATA>) { if(/ORIGINATION_ATTEMPT/) { my $Tid = findTID(); print "$Tid,$Tids{$Tid}{'FIRST_NUMBER'},", "$Tids{$Tid}{'SECOND_NUMBER'}\n"; } } #close(IN); print "============================================\n"; foreach my $Tid (keys(%Tids)) { print "$Tid,$Tids{$Tid}{'FIRST_NUMBER'},", "$Tids{$Tid}{'SECOND_NUMBER'}\n"; } print Dumper \%Tids; ## subroutines sub findTID { my $line=(<DATA>); if($line =~ /Tid: ([0-9a-f]{8})/) { my $Tid = substr($1,3,5); $Tids{$Tid}{FIRST_NUMBER} ="----------"; $Tids{$Tid}{SECOND_NUMBER}="----------"; findNumbers ($Tid); return ($Tid); } } sub findNumbers { my $Tid = shift; my $line=""; while($line=<DATA>, $line !~ /\-{30,}/) { if($line =~ /FIRST_NUMBER\s+(\d+)\s/) { $Tids{$Tid}{'FIRST_NUMBER'}=$1; } if($line =~ /SECOND_NUMBER\s+(\d+)\s/) { $Tids{$Tid}{'SECOND_NUMBER'}=$1; } } } =prints ############################### d1234,9876,9999 a4321,1234,---------- a9999,----------,3333 ============================================ a9999,----------,3333 a4321,1234,---------- d1234,9876,9999 $VAR1 = { 'a9999' => { 'SECOND_NUMBER' => '3333', 'FIRST_NUMBER' => '----------' }, 'a4321' => { 'SECOND_NUMBER' => '----------', 'FIRST_NUMBER' => '1234' }, 'd1234' => { 'SECOND_NUMBER' => '9999', 'FIRST_NUMBER' => '9876' } }; =cut ###################################### __DATA__ --------ORIGINATION_ATTEMPT-------- Tid: abcd1234 FIRST_NUMBER 9876 SECOND_NUMBER 9999 --------------------------------------- --------ORIGINATION_ATTEMPT-------- Tid: defa4321 FIRST_NUMBER 1234 --------------------------------------- --------ORIGINATION_ATTEMPT-------- Tid: defa9999 SECOND_NUMBER 3333 ---------------------------------------

In reply to Re: multidimensional hash value seems to become unitialized by Marshall
in thread 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.