in reply to Re: diamond operator multiple input
in thread diamond operator multiple input

As there are two "things" I'd consider statements I'd rather use the usual form of for().

for my ($dginput, $volinput) { $_ = lc <>; chomp; }
I find it less confusing. This is not golf.

Update: Whoops. That's what I get for not testing the code. No it would not work in 5.10 either. Forget everything I said, you'd have to write it like this:

my ($dginput, $volinput); for ($dginput, $volinput) { $_ = lc <>; chomp; }
Even if I fix the syntax error (by adding one more pair of braces) the variables to not stay declared outside the loop. So it might have been less confusing, but it was plain wrong. Sorry.

Replies are listed 'Best First'.
Re^3: diamond operator multiple input
by graff (Chancellor) on Jan 22, 2009 at 03:17 UTC
    Is that "for" loop syntax something that was introduced with 5.10? I tried that script with 5.8.8 and had two problems with it. First, the snippet as you posted it gave me this sort of error:
    $ perl -e 'use strict; for my ($d,$v){ $_=lc<>; chomp; } print "got $d and $v\n"' Missing $ on loop variable at -e line 1.
    I could get rid of that with an extra set of parens, but then there were scoping issues, because the two variables were limited to the scope of the "for" loop:
    $ perl -e 'use strict; for (my($d,$v)){ $_=lc<>; chomp; } print "got $d and $v\n"' Global symbol "$d" requires explicit package name at -e line 2. Global symbol "$v" requires explicit package name at -e line 2. Execution of -e aborted due to compilation errors.
    Interestingly, neither of those problems seems to affect GrandFather's snippet -- the following not only compiles, but when you feed it data, it does what it's supposed to do:
    $ perl -e 'use strict; ($_=lc <>), chomp for my ($d,$v); print "got $d and $v\n"'
    Again, I'm only looking at 5.8.8 -- it would be good to know whether 5.10 has different behavior in this regard.