in reply to Re^2: Autovivification of scalars in sub calls
in thread Autovivification of scalars in sub calls
Or this ugly situation...:my $var=3; mysleep($var); # these two lines are fine mysleep(3); # but this one causes an error!!! sub mysleep { sleep($_[0]); $_[0]=10; }
$y=substr("hello",10,1); foo($y);# this runs, but substr() generates warnings because the subst +r() is outside the string foo( substr("hello",10,1) ); # this is a fatal error!
Why is it a fatal error? Well, because an invalid substr() is used in a lvalue context. Why is it an lvalue context? Because the subroutine *could* modify the value, and perl isn't smart enough to check to see if it does or not! Worse yet, substr() fails silently on such a fatal error, after generating the *same* warning that's nonfatal in a non-lvalue context. ***SIGH***
I've made it my policy to avoid lvalues() where possible, especially after that substr() issue killed our production code, and wasted a few hours of my time!
--
Ytrew Q. Uiop
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Autovivification of scalars in sub calls
by truedfx (Monk) on Dec 09, 2005 at 11:51 UTC |