in reply to Re^2: Cannot dereference hash in subroutine....
in thread Cannot dereference hash in subroutine....

At a guess, because outside of this subroutine you are accessing the hash, whereas in this subroutine you are using a reference to the hash.

--
<http://www.dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

  • Comment on Re^3: Cannot dereference hash in subroutine....

Replies are listed 'Best First'.
Re^4: Cannot dereference hash in subroutine....
by bigtiny (Acolyte) on Jul 18, 2005 at 15:24 UTC
    Uhhh....I got that! But what I mean is, the reference points to the hunk of memory where the data structure resides, correct? So if I can print the data in main, not using a reference, then that tells me that the data and its structure exist, right? So, I think the problem (and maybe you're saying the same thing) is that when I'm using the reference in the subroutine, I'm not using the proper syntax in the foreach loops to reference these data...however, the data (and their structure) are there in memory....Is my understanding of this correct? If so, then my question is, HOW do I reference these data in the subroutine so that I can 'get at' them in the inner loops? bigtiny

      Yes, that's exactly what I'm saying.

      Within your subroutine your have a reference to a hash (in $mp3hash). The way to look up a value in a hash that you only have a reference to is to use $mp3hash->{KEYNAME}. You are using $mp3hash{KEYNAME} (without the dereferencing arrow). The syntax that you are using is trying to look up a value in the hash %mp3hash, but you don't have a hash called %mp3hash, you have a hash reference called $mp3hash. There's an important difference between the two.

      And, as I said in my first post on this thread, if you were using use strict in your code then Perl would tell you that you were trying to access an unknown variable.

      --
      <http://www.dave.org.uk>

      "The first rule of Perl club is you do not talk about Perl club."
      -- Chip Salzenberg