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


in reply to If exists (hash)

You're using $xml as a scalar element, but exists requires a hash or array element. Also, remember to declare all of your variables. You forgot to declare $image. Here's the way that I would do it:
#!/usr/bin/perl use strict; use warnings; use XML::Simple; use Data::Dumper::Concise; my %xml; my $image; my $web = 'http://my-base-url/'; if(exists $xml{'result'}{'covers'}{1}{'content'}) { print Dumper($image = "$web$xml{'result'}{'covers'}{1}{'content +'}"); } else { print Dumper($image = "$web$xml{'result'}{'covers'}"); }