epoptai has asked for the wisdom of the Perl Monks concerning the following question:
But if there's more, say two lines, we get this:$data = { 'foo' => { 'one' => '1', 'two' => '2' } };
Thanks to a lesson from dkubb on references i know how to extract the data from either one, and setup some conditions to check if we have one or the other, but one still fails if the other succeeds.$data = { 'foo' => [{ 'one' => '1', 'two' => '2' }, { 'one' => '1', 'two' => '2' }] };
If there's multiple cb lines the condition checking for one line:
fails with "Bad index while coercing array into hash"if(exists $data->{'foo'}->{'one'}){ ..code.. }
And if there's one line the condition checking for multiple lines:
fails with "Not an ARRAY reference".if(defined @{$data->{'foo'}}){ ..code.. }
I can see why this is happening, and pretty much understand the errors, but don't know how to properly test these conditions and escape the catch-22. Thanks in advance to whoever saves me from endless hours of "hack, hack, hack, did that work?" debugging.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Testing Complex Data Structures
by btrott (Parson) on Feb 26, 2001 at 22:31 UTC | |
by tye (Sage) on Feb 26, 2001 at 22:38 UTC | |
|
Re: Testing Complex Data Structures
by mirod (Canon) on Feb 26, 2001 at 22:29 UTC | |
by epoptai (Curate) on Feb 27, 2001 at 16:00 UTC | |
|
(tye)Re: Testing Complex Data Structures
by tye (Sage) on Feb 26, 2001 at 22:28 UTC |