Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
This may be more useful as a parser for simple command line arguments if you call it with {@ARGV}

But there are lots of better ways to do that - this a very lightweight way.

I've recently (last 3-4 months or so) been using named parameter lists for almost all my library code and also using Params::Validate, so my idomatic (OO) code looks like

package Chopper::Reed; use Params::Validate qw/validate_with/; sub psychotic { my $self = shift; my %params = validate_with(params => \@_, spec => { punch => 1, charm => {default => 'JOURNALIS +T', regex = qr/^[CON]/} +, mutilate => 0, }, ); $self->mutilate($params{$mutilate}) if $params{$mutilate}; ... } ... 1;
Note: Chopper Reed is self confessed hitman and was sectioned as a self-mutilator whilst serving time in prison for murder. He has been released, is a successful media personality and author, and recently bought a brewery. He recently left his wife and farm in Tasmania because he "...didn't like the septic loo backing up."

+++++++++++++++++
#!/usr/bin/perl
use warnings;use strict;use brain;


In reply to Re: Perl Idioms Explained - my ($foo, $bar) = @{shift(@_)}{qw/ -foo -bar /} by leriksen
in thread Perl Idioms Explained - my ($foo, $bar) = @{shift(@_)}{qw/ -foo -bar /} by Roger

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-03-28 15:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found