Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris
 
PerlMonks  

Re: What does the dash before hash assignment means?

by sundialsvc4 (Abbot)
on Sep 03, 2013 at 12:13 UTC ( #1052092=note: print w/ replies, xml ) Need Help??


in reply to What does the dash before hash assignment means?

fun(-url => $httpRefer ); is not a “hash assignment.”   The => symbol in this case is equivalent to a comma.   Subroutine fun is being called with an argument-list containing two arguments:   -url, and the value of $httpRefer.

Some subroutines are written to recognize and to assign particular meanings to parameters which begin with a dash, e.g. to disambiguate user-chosen arbitrary strings which otherwise might match “real” parameters for the function.   (I, the author, decree that ... “Anything beginning with a dash is a literal.”)   But, that is up to their authors, not Perl itself.


Comment on Re: What does the dash before hash assignment means?
Re^2: What does the dash before hash assignment means?
by karlgoethebier (Vicar) on Sep 03, 2013 at 13:50 UTC
    "...is not a hash assignment"

    It is.

    #!/usr/bin/env perl + use strict; use warnings; print fun(-nose =>'cuke') . qq(\n); sub fun { my %args = @_; return $args{-nose}; } __END__ karls-mac-mini:monks karl$ ./fun.pl cuke

    «The Crux of the Biscuit is the Apostrophe»

      Not really - the arguments to the function call construct a list:

      -nose =>'cuke' # even-sized list

      The hash assignment happens here:

      my %args = @_;

        OK, thats true.

        Thanks, Karl

        «The Crux of the Biscuit is the Apostrophe»

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2015-07-03 03:03 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (47 votes), past polls