Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

Re: Parsing hashes with variable structure

by jethro (Monsignor)
on Nov 09, 2012 at 01:55 UTC ( #1003045=note: print w/replies, xml ) Need Help??

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003045]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2018-04-23 10:19 GMT
Find Nodes?
    Voting Booth?