Data is been meticulous and been complex now a day especially when writing your Perl scripts or other scripting language.
Data is essential to us. I write up a Perl script that will get data from a certain XML structure but upon running my script I’ve encounter this error.
$rejXTags = $data->{getINFO}->{SUBJ}->{BODY}->{CONCERN}->{ERROR_INFO}->{ERROR_DESC};
Bad index while coercing array into hash
The index looked up in the hash found as the 0′th element of a pseudo-hash is not legal. Index values must be at 1 or greater.
Here are the solution that I used to keep my script running:
- Use Data::Dumper to determine what type of data it is. Array or Hash or either the combination of two that’s make it more complex to sort.
Sample:
use Data::Dumper;
print Dumper($xmld->{Recreation}[0]);
- Then, separate the on how you get the data or simply a if else statement will be great.
if (array $var) {
.. work with the array
} else {
... work without an array
}
Viola! and your done!


Leave Your Comments Below