>>>>> "BR" == Bob Rogers <[EMAIL PROTECTED]> writes:
BS> From: Bogart Salzberg <[EMAIL PROTECTED]>
BS> Date: Fri, 23 Jul 2004 12:56:31 -0400
BS> I watered down the production code and ran a test version on
BS> different servers (see below). To sum it up, this line works on the
BS> new and not on the old, and I'm wondering if there is a "low-profile"
BS> workaround:
BS> my ($process, $target) = wantarray? (\&push_array, [EMAIL PROTECTED]):
BS> (\&concat, \$record);
BR> If I run your script with "-w", I get this warning:
BR> Useless use of reference constructor in void context at
BR> ./perl-test.pl line 28.
BR> But I have no clue what that means.
It's referring to the third "\" operator. The second comma operator is
being evaluated in void context, so the value on its left side,
\&concat, will be thrown away ("void context"). Because taking that
reference has no side effects, Perl thinks it's silly to do if it's
just going to be thrown away.
BR> However, I note that it works if I
BR> rewrite the line above as follows:
BR> my $process = wantarray ? \&push_array : \&concat;
BR> my $target = wantarray ? [EMAIL PROTECTED]: \$record;
BR> Better (and still working) is:
BR> my $wa = wantarray;
BR> my ($process, $target) = $wa ? (\&push_array, [EMAIL PROTECTED]): (\&concat,
\$record);
BR> So it would appear to be some bug relating to the '?' operator
BR> with lists appearing in the result clauses and wantarray appearing
BR> in the conditional. I bet the warning means that the line is
BR> being misparsed somehow. But more than that I wouldn't venture to
BR> say.
Yes. The bug, which existed all the way back to the earliest versions
of Perl 5, was an overactive optimization. Whenever you wrote
something like "wantarray ? FOO : BAR", FOO was always put in list
context, and BAR was always put in scalar context. This was correct
when the ?: was the last expression in the sub, or the argument to
return. It wasn't correct in general, though, when there might be some
other context propagating from the rest of the expression, like the
list context in your example.
The bug was fixed a bit more than two years ago, by change #17423, in
between 5.8.0 RC2 and 5.8.0 RC3. Bug #9998 has more details.
-- Stephen
_______________________________________________
Boston-pm mailing list
[EMAIL PROTECTED]
http://mail.pm.org/mailman/listinfo/boston-pm