Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

RE: Passing named parameters

by ChOas (Curate)
on May 02, 2000 at 10:50 UTC ( [id://9901]=note: print w/replies, xml ) Need Help??


in reply to Passing named parameters

Hi!

Eeehm you might want to put ' thingies around your
keys aswel that hash, that might help

and for B:
I'd think this'd work:
sub do_this_cool_function(@)
{
my %Param=@_;
# Now address your params like this:
my $When=$Param{'-retire'};
my $Wages=$Param('-payscale'};
my $Favourite_temperature=$Param{'-pizza'};

}
That's how I'd do it.

Replies are listed 'Best First'.
RE: RE: Passing named parameters
by perlmonkey (Hermit) on May 02, 2000 at 11:38 UTC
    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".
      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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://9901]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (6)
As of 2024-04-23 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found