in reply to something about improving code...
The precedence of de-reference $ and array subscript [] mean that what you wrote doesn't work. You need those ${ ... } de-reference brackets for all de-references except the simplest.sub flip { ${$_[0]} = !${$_[0]} };
Note also that you meant $_[0] rather than @_[0] didn't you ;-)
Interestingly
Isn't a syntax error and doesn't produce any warnings but does something completely unintended.sub flip { $$_[0] = !($$_[0]) }
I don't understand why this doesn't print use of unitialised variable or something like that...perl -w -e 'use strict; sub flip { $$_[0] = !($$_[0]) }; my $z=1; fl +ip(\$z); print "$z\n"' 1
|
|---|