SPUG: Too long to find bug: Fat comma and assignment look similar, and have some similar meaning

Ivan Heffner iheffner at gmail.com
Fri Jan 15 16:11:58 PST 2010


This is a contrived example, but since Perl doesn't actually
distinguish between fat and skinny comma (or translates the fat commas
into skinny commas and it is purely human brains that give "special
meaning" to fat commas) this is syntactically and semantically valid,
even though it is idiomatically misleading.

use strict;
use warnings;

my $x;

# some more complicated stuff

(my $y => $x) = get_stuff();

print "x: $x; y: $y;\n";

sub get_stuff {
	return rand 2, rand 3;
}

-- 
Ivan

On Thu, Jan 14, 2010 at 11:59 AM, Michael R. Wolf <MichaelRWolf at att.net> wrote:
>
> On Jan 14, 2010, at 11:50 AM, Charles DeRykus wrote:
>
>> 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 ..
>
>
> And similar warnings for other bare words...
>
> my $x => my_func;               # Warning
> my $x => my_func();     # No warning
>
> --
> Michael R. Wolf
>    All mammals learn by playing!
>        MichaelRWolf at att.net
>
>
>
>
> _____________________________________________________________
> Seattle Perl Users Group Mailing List
>    POST TO: spug-list at pm.org
> SUBSCRIPTION: http://mail.pm.org/mailman/listinfo/spug-list
>   MEETINGS: 3rd Tuesdays
>   WEB PAGE: http://seattleperl.org/
>


More information about the spug-list mailing list