On Nov 7, 3:24 pm, Paul Lalli <mri...@gmail.com> wrote:
> On Nov 7, 9:18 am, sheinr...@my-deja.com wrote:
>
>
>
> > Why does this line work as expected
>
> > print qw(A B C D E F G H)[split //, '76543210'], "\n"; # outputs
> > "HGFEDCBA"
>
> > but this one doesn't compile:
>
> > print (split //, 'ABCDEFGH')[split //, '76543210'], "\n"; # syntax
> > error at ..., near ")["
>
> > ???
>
> > Is there a tweak to make the 2nd version work as well?
> > I tried some combinations with @(), @{} but didn't get it working.
>
> > Eplanation and remedy would both be appreciated.
>
> If it looks like a function, it acts like a function. What that means
> is that if a function like print is immediately followed by a
> parenthesis, then the parentheses enclose the arguments to the
> function. So in your example, the arguments to print stopped at
> the ), and the rest therefore makes no sense.
>
> To solve, you can either enclose everything you meant to print in
> parentheses:
> print ((split //, 'ABCDEFGH')[split //, '76543210'], "\n");
> or stick a + in front of the first (
> print +(split //, 'ABCDEFGH')[split //, '76543210'], "\n";
>
> Paul Lalli
<slapping my forehead>
.... and if I'd have used warnings as I usually do it would have said:
"print (...) interpreted as function"
Thanks a lot pal!
|