Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

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"


Comment on Re: Parsing hashes with variable structure
Select or Download Code
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1003045]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (5)
As of 2014-11-25 00:57 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My preferred Perl binaries come from:














    Results (148 votes), past polls