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

Warn on "x" in wrong context ?

Thread Previous | Thread Next
From:
M.J.T. Guy
Date:
February 17, 2000 06:49
Subject:
Warn on "x" in wrong context ?
Message ID:
E12LSEs-0002hR-00@ursa.cus.cam.ac.uk
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;
when 
           @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


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