[comp.lang.perl] push bug?

nagel@paris.ics.uci.edu (Mark Nagel) (01/18/90)

The following line causes perl 3.0p8 to crash with a syntax error
during compilation:

    push(($hdrval{$CTL} eq "" ? @ngrps : @ygrps), $grp);       

syntax error in file /tmp/pdb25979 at line 263, next 2 tokens "(("
Execution aborted due to compilation errors.

Should it?  The associative array hdrval and other variables are OK,
it just seems like perl is unwilling to accept the ternary operator
as an array in this context.
-- 
Mark Nagel
UC Irvine Department of ICS   +----------------------------------------+
ARPA: nagel@ics.uci.edu       | Charisma doesn't have jelly in the     |
UUCP: ucbvax!ucivax!nagel     | middle.  -- Jim Ignatowski             |

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) (01/19/90)

In article <25B55917.26081@paris.ics.uci.edu> nagel@paris.ics.uci.edu (Mark Nagel) writes:
: The following line causes perl 3.0p8 to crash with a syntax error
: during compilation:
: 
:     push(($hdrval{$CTL} eq "" ? @ngrps : @ygrps), $grp);       
: 
: syntax error in file /tmp/pdb25979 at line 263, next 2 tokens "(("
: Execution aborted due to compilation errors.
: 
: Should it?  The associative array hdrval and other variables are OK,
: it just seems like perl is unwilling to accept the ternary operator
: as an array in this context.

Whether that should work or not depends on whether you think ?: should
transitively pass on lvalue-hood to it's 2nd and 3rd arguments.  The
first argument of push must be an lvalue, actually, though that's
enforced in yacc, not the usual lvalue checker, hence the "syntax error"
rather than a more useful "Illegal lvalue" message.

I don't think ?: should be allowed as an lvalue.  If you really want
to do something like that, you could use the * aliasing mechanism to say

	local(*tmp) = $hdrval{$CTL} eq "" ? *ngrps : *ygrps;
	push(@tmp,$grp);

Admittedly, not as concise.  But then, I don't allow

	($maybe ? $foo : $bar) = 1234;

either.

Larry

nagel@ics.uci.edu (Mark Nagel) (01/20/90)

lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes:

>I don't think ?: should be allowed as an lvalue.  If you really want
>to do something like that, you could use the * aliasing mechanism to say

>	local(*tmp) = $hdrval{$CTL} eq "" ? *ngrps : *ygrps;
>	push(@tmp,$grp);

>Admittedly, not as concise.  But then, I don't allow

>	($maybe ? $foo : $bar) = 1234;

>either.

OK, I guess I just viewed push as a function of sorts and I was just
selecting a parameter.  From what you say, it is really an
operator.  I can live with that.

Mark
--
Mark Nagel
UC Irvine Department of ICS   +----------------------------------------+
ARPA: nagel@ics.uci.edu       | Charisma doesn't have jelly in the     |
UUCP: ucbvax!ucivax!nagel     | middle.  -- Jim Ignatowski             |