http://www.perlmonks.org?node_id=1003045


in reply to Parsing hashes with variable structure

Is your problem solved with the addition of {} around $usernumber or was that a copy mistake? If the problem still exists, read on:

#!/usr/bin/env perl use warnings; use strict; use 5.10.0; my $h= { 'user' => { 'firstname' => 'Joe','lastname' => 'Shmoe'}}; my $h2= { 'user' => 'Finance Department'}; say "yes" if (ref($h->{'user'}) eq "HASH"); say "no" if (not ref($h2->{'user'}) eq "HASH"); #OUTPUT: yes no

As you can see ref() works. So probably you feed the wrong data to ref(). You could use Data::Dumper to print out your $xml to see if it fits your expectation. And print out $xml->{$usernumber}->{"user"} just before your "if"-clause to check what it contains at that crucial moment. If ref() returns "HASH" then you can be really sure that it is a hash that is in there and not the string "Finance Department"

Replies are listed 'Best First'.
Re^2: Parsing hashes with variable structure
by SomeNoob (Initiate) on Nov 12, 2012 at 19:53 UTC

    Thanks so much! ref() did work; I must have made some kind of mistake when I tried it before. Again, thanks a ton for helping me out.