in reply to Re: " - " in the syntax
in thread " - " in the syntax

It stringifies things that look like strings on the left, no spaces, no sigils (% @ $), only letters/numbers/dash/underscore

Replies are listed 'Best First'.
Re^3: " - " in the syntax
by cdarke (Prior) on Mar 06, 2009 at 09:48 UTC
    You sure the - stringifies? Try this:
    use strict; use warnings; use Data::Dumper; my %a = (-keys => 'v1', -values => 'v2'); print Dumper(\%a);
    Gives (as expected):
    $VAR1 = { '-keys' => 'v1', '-values' => 'v2' };
    keys and values are (of course) builtins. When I replace the 'fat comma' with an ordinary one:
    my %a = (-keys , 'v1', -values , 'v2');
    I get:
    Not enough arguments for keys at C:\gash.pl line 6, near "keys ," Not enough arguments for values at C:\gash.pl line 7, near "values ,"
    It was the fat comma doing the stringification, not the -.

    Update: Re-reading the previous post, Anon did say "things that look like strings", which is correct. keys and values "look like" Perl builtins. Changing the names gives different results:
    my %a = (-xkeys , 'v1', -xvalues , 'v2');
    Gives:
    $VAR1 = { '-xvalues' => 'v2', '-xkeys' => 'v1' };
    Which I guess means it is not a good idea to rely on - to do stringification.
      It, A fat comma string-ifies what's on the left of it...that only if it looks like a string.
        See my first example. It appears that what looks like a string to a fat comma is diffferent to what looks like a string to a leading hyphen.
        my %a = (keys => 'v1', values => 'v2');
        gets stringified correctly, but:
        my %a = (-keys , 'v1', -values , 'v2');
        does not.