in reply to " - " in the syntax

It is part of the identifiers on the left-hand side of the fat commas denoted by =>

A fat comma string-ifies what's on the left of it, such that
(-title => "The Time", -bgcolor => "#ffffff")

is the same as
("-title", "The Time", "-bgcolor", "#ffffff")

It so happens that the "-" at the beginning also string-ifies a bareword, such that
(-title, "The Time", -bgcolor, "#ffffff")

also yields
("-title", "The Time", "-bgcolor", "#ffffff")

Replies are listed 'Best First'.
Re^2: " - " in the syntax
by plobsing (Friar) on Mar 06, 2009 at 05:14 UTC

    This got me curious

    $ perl -MO=Deparse -e 'print $q -> start_html(-title => "The Time", -b +gcolor => "#ffffff") ' print $q->start_html(-'title', 'The Time', -'bgcolor', '#ffffff'); -e syntax OK $ perl -MO=Deparse -e 'print -"asdf"' print '-asdf'; -e syntax OK $ perl -MO=Deparse -e 'print -"1asdf"' print -1; -e syntax OK $ perl -MO=Deparse -e 'print -"-1asdf"' print '+1asdf'; $ perl -MO=Deparse -e 'print -"+1asdf"' print '-1asdf'; -e syntax OK

    What I glean from this is that if you use unary minus on any non-numish-looking string constant, the minus will get prepended. If you use an undecorated(+/-) numish string constant it gets numified, but if you use a decorated one it inverts the sign and doesn't numify?

    Is this accurate?
    Is this documented anywhere?
    What is the rule on this?
    And what is this useful for (beyond use given in the OP)

      Did you read Symbolic-Unary-Operators?

      $ perl -MO=Deparse -e 'print -"asdf"' print '-asdf'; -e syntax OK
      If the operand is an identifier, a string consisting of a minus sign concatenated with the identifier is returned.
      $ perl -MO=Deparse -e 'print -"1asdf"' print -1; -e syntax OK
      If, however, the string begins with a non-alphabetic character (excluding "+" or "-"), Perl will attempt to convert the string to a numeric and the arithmetic negation is performed.
      $ perl -MO=Deparse -e 'print -"-1asdf"' print '+1asdf'; $ perl -MO=Deparse -e 'print -"+1asdf"' print '-1asdf'; -e syntax OK
      Otherwise, if the string starts with a plus or minus, a string starting with the opposite sign is returned.
      --
      seek $her, $from, $everywhere if exists $true{love};
Re^2: " - " in the syntax
by Anonymous Monk on Mar 06, 2009 at 09:25 UTC
    It stringifies things that look like strings on the left, no spaces, no sigils (% @ $), only letters/numbers/dash/underscore
      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.