shemp has asked for the wisdom of the Perl Monks concerning the following question:
This worked ok, even when $arrayref == undef. So then i added an if conditional to the method:my $arrayref = getArrayref(); # this sometimes returned undef foreach my $value (@$arrayref) { ... }
This resulted in a fatal error:if ( @$arrayref ) { ... }
Can't use an undefined value as an ARRAY reference at ...
My co-worker and I discussed this and decided that it was an rvalue versus lvalue issue. But our resolution still doesn't sit very well in my mind.
Anyway, in the end i did the if statement as:
(perhaps i should be doing a ref test also, but the value of $arrayref is always set by the same method.)if ( defined($arrayref) && @$arrayref ) { ... }
So im looking for more insight into exactly why this is all behaves like it does. I sort of understand, but not completely.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Using undef scalar as arrayref
by ikegami (Patriarch) on Aug 12, 2005 at 20:38 UTC | |
|
Re: Using undef scalar as arrayref
by Joost (Canon) on Aug 12, 2005 at 20:15 UTC | |
by shemp (Deacon) on Aug 12, 2005 at 20:36 UTC | |
by Joost (Canon) on Aug 12, 2005 at 20:44 UTC | |
by shemp (Deacon) on Aug 12, 2005 at 21:07 UTC |