awohld has asked for the wisdom of the Perl Monks concerning the following question:

I've searched and read all over but can't figure this out.

I have this "$hash_ref" that comes from a DB query using "$dbh->selectall_hashref" in the DBI.

As seen from Data::Dumper this is my data:
$VAR1 = { '1' => { 'PointType' => 'Camera', 'idType' => '1' }, '2' => +{ 'PointType' => 'School', 'idType' => '2' } };
If I want to just get the "PointType" by knowing the "idType" how would I do that?

I've guessed $hash_ref{'1'} or $hash_ref->{'1'} hoping to get "Camera" back but it doesn't work.

How do I do this, I'm lost?

Replies are listed 'Best First'.
Re: Accessing Element in a Hash Reference
by Zaxo (Archbishop) on Sep 14, 2005 at 07:42 UTC

    Close, $hash_ref->{'1'}->{'PointType'} or $hash_ref->{'1'}{'PointType'}

    You have two levels, so you need two keys.

    After Compline,
    Zaxo

      Wow, I guessed a structure close to that, my beginners Perl books don't have that info in them, maybe I'm finally getting out of "beginners" mode. :) Thanks