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

Hello, I am importing an XML document using XML::Simple. If the user is validated, I get this (using Data::Dumper):
$VAR1 = 'true';
Otherwise, I get this:
$VAR1 = { 'request' => [ '/account/verify_credentials.xml' ] 'error' => [ 'Could not authenticate you.' ] }
I am trying to check to see if the user was rejected by starting with if(defined $data->{error}). If the user was in fact verified, I get this run time error: Can't use string ("true") as a HASH ref while "strict refs" in use at.... Thanks for any advice.

Replies are listed 'Best First'.
Re: Checking the layout of a data structure.
by Fletch (Bishop) on Dec 05, 2008 at 20:12 UTC

    So just check if you have a reference or not before trying to use it as such.

    The cake is a lie.
    The cake is a lie.
    The cake is a lie.

      Hmm, silly question I guess. I just changed if(defined $data->{error}) to if(ref $data) et voilą! I suppose I was assuming "defined" would come into action before the dereferencing arrow. Many thanks.