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

Warn on "x" in wrong context ?

Thread Previous | Thread Next
M.J.T. Guy
February 17, 2000 06:49
Warn on "x" in wrong context ?
Message ID:
Having just been bitten for the 29,413rd time, I think it would be
a Good Thing if the repetition operator warned if the scalar form was
used in list context, i.e. when you accidentally write

           @array = $val x $count;
           @array = ($val) x $count;

was intended.    Currently, it just silently produces the wrong answer.
This is a common style of code, for example when initialising a
hash slice to TRUE flags.

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

Mike Guy

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About