[sf-perl] Unusual Perl "feature"

Mark Kvale kvale at phy.ucsf.edu
Fri Feb 15 16:14:25 PST 2013


On 02/15/2013 03:58 PM, Earl Ruby wrote:
> I made a typo and found a new feature.
>
> I have no idea what this feature is for:
>
>> perl -e 'use strict; my $name = - "NAME"; print "$name\n"; print "Perl prepended a minus sign to my string\n" if $name eq "-NAME";'
> -NAME
> Perl prepended a minus sign to my string
>
> Interesting behavior. Can anyone give me an example of what is this used for?
>
> --
> Earl Ruby
> http://earlruby.org/
> http://www.linkedin.com/in/earlruby
> @earlruby
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm
>

This is documented behavior; see

http://perldoc.perl.org/perlop.html#Symbolic-Unary-Operators

My guess on use? As the man says, '-bareword is equivalent to the string 
"-bareword"', allowing for fat comma keys without needing quotes, e.g.

(-bareword => 1, -title => 2)


Mark


More information about the SanFrancisco-pm mailing list