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

Re: Warn on "x" in wrong context ?

M.J.T. Guy
February 17, 2000 07:48
Re: Warn on "x" in wrong context ?
Message ID:
Tom Christiansen <> 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 Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About