in reply to Re^2: arrays: shifting in while loop
in thread arrays: shifting in while loop
When you get a message like "print (...) interpreted as function ...", you can typically disambiguate your statement for Perl by simply adding a + in front of the opening parenthesis.
Your original code runs like this:
ken@ganymede: ~/local/bin $ perl -Mstrict -Mwarnings -E 'my $s = "foo bar baz qux 3 3 1 3"; my @ +a = split /\s/, $s; splice(@a, 0, 4); while (@a) { print (shift @a), +(shift @a), "\n"; }' print (...) interpreted as function at -e line 1. Useless use of a constant ( ) in void context at -e line 1. 31ken@ganymede: ~/local/bin $
Adding a single + (changing ... print (... to ... print +(...), you get the output you were after:
ken@ganymede: ~/local/bin $ perl -Mstrict -Mwarnings -E 'my $s = "foo bar baz qux 3 3 1 3"; my @ +a = split /\s/, $s; splice(@a, 0, 4); while (@a) { print +(shift @a), + (shift @a), "\n"; }' 33 13 ken@ganymede: ~/local/bin $
This is discussed in more detail in perlop - Symbolic Unary Operators.
-- Ken
|
|---|