SPUG: Too long to find bug: Fat comma and assignment look similar, and have some similar meaning
derykus at gmail.com
Thu Jan 14 11:50:26 PST 2010
On Thu, Jan 14, 2010 at 9:07 AM, Michael R. Wolf <michaelrwolf at att.net>wrote:
> use strict;
> use warnings;
> my $x => rand;
> die 'Did you notice fat comma instead of assignment? Variable did not >
set' unless defined $x;
> In retrospect, what had me miss it was:
> 1 - the visual similarity between '=' and '=>'
> 2 - the similarity of meaning between "gets" (assignment) and "gets
> associated with" (fat comma's common use in creating hash key/value >
> Can you think of a good use of fat comma (or skinny comma, for that
> matter) in this context? Or, framed differently, why shouldn't (or can't)
> get a warning like "Strange mixture of declaration, stringification, and
> function call in void context"?
I can't think of good use for fat/skinny comma in that context but
maybe a more devious mind is needed..
It does seem odd that rand (srand too) don't warn since other
arithmetic functions do:
perl -wle 'my $x => sin'
Useless use of sin in void context ...
Use of uninitialized value $_ in sin ...
and similiar warnings for cos, exp, int, log ..
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the spug-list