Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Understanding arguments to subroutines

by uday_sagar (Scribe)
on May 14, 2012 at 12:35 UTC ( [id://970415]=note: print w/replies, xml ) Need Help??


in reply to Re: Understanding arguments to subroutines
in thread Understanding arguments to subroutines

I know the use of fat comma, in the context of a hash, but here, hyphen (-) is also used with "verbose" which confuses me a bit.
  • Comment on Re^2: Understanding arguments to subroutines

Replies are listed 'Best First'.
Re^3: Understanding arguments to subroutines
by cdarke (Prior) on May 14, 2012 at 12:45 UTC
    The hyphen is a bit of a throw-back to olden-times. This originally meant that the caller did not need to quote the keys – although that has not been required since version 5.6 and that functionality passed to the fat comma. The hyphen is not stripped off by perl, it is passed in @_ so the subroutine has to remove it.
Re^3: Understanding arguments to subroutines
by toolic (Bishop) on May 14, 2012 at 14:19 UTC
    Take a look at the source code perldoc -m Pod::Usage:
    sub pod2usage { local($_) = shift; my %opts; # ... ## Now determine default -exitval and -verbose values to use if ((! defined $opts{'-exitval'}) && (! defined $opts{'-verbose'}) +) { $opts{'-exitval'} = 2; $opts{'-verbose'} = 0; }

    -verbose is used verbatim as a hash key.

Re^3: Understanding arguments to subroutines
by Corion (Patriarch) on May 14, 2012 at 12:41 UTC

    You can ask Perl directly to show its interpretation:

    > perl -MO=Deparse -e "-verbose" -'verbose'; -e syntax OK

    The minus is an unary minus, also documented in perlop.

Re^3: Understanding arguments to subroutines
by DStaal (Chaplain) on May 14, 2012 at 15:11 UTC

    It makes it easier to differentiate 'argument tags' from 'argument values', especially in mixed contexts. It doesn't necessarily mean anything to perl, but it means something to the subroutine.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (5)
As of 2024-04-24 22:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found