develooper Front page | perl.perl5.porters | Postings from February 2000

Re: Warn on "x" in wrong context ?

From:
M.J.T. Guy
Date:
February 17, 2000 07:48
Subject:
Re: Warn on "x" in wrong context ?
Message ID:
E12LTAK-0006GD-00@ursa.cus.cam.ac.uk
Tom Christiansen <tchrist@chthon.perl.com> wrote, quoting me:
> I sympathize.  My own recurring fualt is different
> form yours.  I often forget and write:
> 
>     @x = @y x 3;
> 
> rather than 
> 
>     @x = (@y) x 3;

Yes, I make that mistake too.    Ideally, the Perl DWIM should know
that's the list case, making it the same as the LHS of an assignment.
But it's obviously far too late to change that now.

> >If the first form is *really* needed (an implausible story), you can
> >always use scalar().
> 
> Are you sure?

Well, it is totally undocumented ...
 
>     %hash = (
> 	a => $a x 1,
> 	b => $b x 2,
> 	c => $c x 2,
>     );

Awww... Rats!     So how about the rule "warn if this happens as the
RHS of an assignment".     That seems to cover the cases I get bitten by.

I suppose there'll be the people who spuriously change scalar
assignments into list ones:

       my ($scalar) = $string x $count;


:-(


Mike Guy



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About