Why does Perl throw a fit at the following snippet?
$ perl -Mstrict -wE '@ARGV ||= ".";'
Can't modify array dereference in logical or assignment (||=) at -e line 1, near "'.';"
Execution of -e aborted due to compilation errors.
While it happily processes
$ perl -Mstrict -wE '@ARGV = @ARGV || ".";'
I don't see the perldiag
explanation helping here much:
Can't modify %s in %s
(F) You aren't allowed to assign to the item indicated, or otherwise try to change it, such as with an auto-increment.
A more human-friendly explanation for this behavior is much appreciated.
It's impossible for the code @ARGV
to both return the array itself and the number of elements in it, so @ARGV ||= '.';
makes no sense. You need to evaluate @ARGV
twice, once in scalar context (to get the number of elements), and once as an lvalue (to get the array itself).
@ARGV = @ARGV || '.';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With