[sf-perl] Unusual Perl "feature"

Sean Dodger Cannon el.dodgero at gmail.com
Tue Feb 19 03:11:50 PST 2013


Technically those aren't barewords in your example. Everything on the
left of a => is implicitly double quotish.

On 15 February 2013 16:14, Mark Kvale <kvale at phy.ucsf.edu> wrote:
> 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
>
> _______________________________________________
> SanFrancisco-pm mailing list
> SanFrancisco-pm at pm.org
> http://mail.pm.org/mailman/listinfo/sanfrancisco-pm



-- 
Sean "Dodger" Cannon


More information about the SanFrancisco-pm mailing list