in reply to RE: Passing named parameters
in thread Passing named parameters

No, this is proper syntax: do_this_cool_function (-retire=>'early', -payscale=>-55.00, -pizza=>'cold', -beer=>none); This should work fine as in many modules like CGI.pm. The leading '-' in -retire will perl to interpret '-retire' as a string. Here is a snip from perlop
Unary "-" performs arithmetic negation if the operand is numeric. If the operand is an identifier, a string consisting of a minus sign concatenated with the identifier is returned. Otherwise, if the string starts with a plus or minus, a string starting with the opposite sign is returned. One effect of these rules is that -bareword is equivalent to "-bareword".

Replies are listed 'Best First'.
RE: RE: RE: Passing named parameters
by Adam (Vicar) on May 09, 2000 at 21:05 UTC
    Which is why -beer isn't a bareword. But the => is equivalent to a , (comma) thus ending the bareword, er string. So then
        -beer, none
    will result in none being a bareword. At least, that's how I understand it.
      You are correct of course.
      non strict code:
      &a(-beer=>none); sub a { print join("=>",@_); }
      This will product the correct results of "-beer=>none" as long as you are not using 'strict' or -w, but of course nobody does that ... right? So to be proper:
      use strict; &a(-beer=>'none'); sub a { print join("=>",@_); }
      and this will product the same results, with no warnings.

        Sorry to reply 4 years later. The - has nothing to do with the string or bareword. The => says qoute whats on my left and pretend i'm a comma. so a(-beer=>none) is the same as a("beer", none); Perhaps this is what the original author meant but I wasn't sure and thought i might clarify a bit.


        ___________
        Eric Hodges