in reply to Using undef scalar as arrayref
If i put this line before the if, then things are ok:That can't work at all:But thats not cool, and results in a warning too.@$arrayref;
#!/usr/bin/perl -w use strict; my $arrayref; @$arrayref; # line 5 print "ok";
Useless use of a variable in void context at test.pl line 5. Can't use an undefined value as an ARRAY reference at test.pl line 5.
Anyway, I suggest using
if $arrayref can only be false (undef) or a real ref.if ($arrayref) { ... }
update: about the if ($arrayref) test: if, as you say, arrayref should be false or an arrayref, there's no reason to do an defined() and ref() test, because if the $arrayref is true it should be an arrayref, and if it's not, there's nothing you can usefully do, except throw an exception, which is what will happen by default:
#!/usr/bin/perl -w use strict; my $arrayref = 1; for (@$arrayref) { print "ok\n"; }
Can't use string ("1") as an ARRAY ref while "strict refs" in use at t +est.pl line 5.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Using undef scalar as arrayref
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 |