This is a bug in Perl relating to pseudohashes, and is fixed in 5.9.0-to-be. There, it gives the more edifying message "Not a HASH reference at ..."
perl -pe '"I lo*`+$^X$\"$]!$/"=~m%(.*)%s;$_=$1;y^`+*^e v^#$&V"+@( NO CARRIER'
| [reply] |
I cooked up this small snippet, which causes XML::Simple to throw an Out of memory!
No, Perl stops with an out of memory error when you
treat an arrayref as a hashref. The print Dumper($xml) line output clearly shows that if you turn on forcearray, you get arrays.
| [reply] [d/l] |
The reason i used the keyattr in my previous
reply was due to a strange quirk within
XML::Simple. Consider this example:
use XML::Simple;
use Data::Dumper;
my $xml = XMLin(\*DATA);
print Dumper $xml;
__DATA__
<documents>
<document>
<stayonhost>1</stayonhost>
<staybelow>1</staybelow>
<maxdepth>2</maxdepth>
<name>Swedish Foo</name>
<home_url>http://www.foo.se/bar/</home_url>
<category>International</category>
</document>
<document>
<stayonhost>0</stayonhost>
<staybelow>0</staybelow>
<maxdepth>3</maxdepth>
<name>Swedish Bar</name>
<home_url>http://www.bar.se/baz/</home_url>
<category>National</category>
</document>
</documents>
and it's output:
$VAR1 = {
'document' => {
'Swedish Foo' => {
'category' => 'International',
'maxdepth' => '2',
'stayonhost' => '1',
'staybelow' => '1',
'home_url' => 'http://www.foo.se/bar/'
},
'Swedish Bar' => {
'category' => 'National',
'maxdepth' => '3',
'stayonhost' => '0',
'staybelow' => '0',
'home_url' => 'http://www.bar.se/baz/'
}
}
};
What happened to the name element? I don't know
for sure, but i am guessing that XML::Simple treats elements
named name differently.* So, i read some docs,
figured that keyattr might fix the problem and it
did. But first i tried forcearray, which didn't
fix the problem. I didn't think it would, but i didn't have
a spare chicken to sacrifice at the time. ;) In case you
are wondering ... forcearray is useful for keeping
XML elements in order, remember that hashes lose order.
forcearray is also useful for keeping your code
consistent - you can always (99.99%?) expect an array, no
guessing with ref needed.
I guess my point is that XML::Simple can handle
tasks that are really beyond its scope, and you should be
wary of that. It's great for getting stuff done quick, but
you probably should pick a more industrial strength module
for serious production code - like XML::Twig.
* yep ... here's what the docs say:
The default value for 'keyattr' is ['name', 'key',
'id']. Setting this option to an empty list will
disable the array folding feature.
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] [d/l] |
| [reply] |