[sf-perl] Unusual Perl "feature"
doom at kzsu.stanford.edu
Tue Feb 19 07:58:39 PST 2013
Sean Dodger Cannon <el.dodgero at gmail.com> wrote:
> Technically those aren't barewords in your example. Everything on the
> left of a => is implicitly double quotish.
my $suffix = 'alpha';
my %fried =
( name => 'okonomiyaki',
mystery_field_$suffix => 'tonkatsu',
# Can't locate object method "mystery_field_" via package "alpha"
(perhaps you forgot to load "alpha"?) at
/home/doom/bin/testes-double_quotish_to_left_of_fat_comma line 56.
> Mark Kvale <kvale at phy.ucsf.edu> wrote:
>> 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";'
>>> Perl prepended a minus sign to my string
>>> Interesting behavior. Can anyone give me an example of what is this used
>> This is documented behavior; see
>> 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)
More information about the SanFrancisco-pm