At 01:45 PM 9/4/00 -0600, Tom Christiansen wrote:
> >package main;
> >sub fn { return (3, 5, 7) }
> >tie $x, 'MaiTai';
> >$x = fn;
> >$ /tmp/foo
> >STORE: 7
>
> >Why don't I see three STOREs?
>
>Because Perl is too clever to bother. :-)

Hey, waitaminute.  That isn't a list in sub fn in the first place; it's 
three expressions separated by scalar commas.  Why is there no complaint 
about useless use of a constant in void context?

$ perl -Mstrict -wle 'sub f{return(3,5,7)} my $x = f()'
$ perl -Mstrict -wle 'my $x = (3,5,7)'
Useless use of a constant in void context at -e line 1.
Useless use of a constant in void context at -e line 1.
$

If context propagates through subroutine calls why no warning?

I find myself wishing there were something we could do about the context 
rules.  They seem simple enough, individually, but when you put them 
together - well, there was a quiz a year or so ago - I forget whether it 
was in TPJ or Usenet - where someone posted 10 or so code fragments and 
challenged readers to figure out what they did.  And they were all very 
simple things on the order of my($x,$y) = ($z,fn($w)).  'Expert' users were 
those who got more than 7 right.  Unfortunately this is an empty gripe 
since I have no idea where to start simplifying.
--
Peter Scott
Pacific Systems Design Technologies

Reply via email to