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

Re: Perl Idioms Explained - my ($foo, $bar) = @{shift(@_)}{qw/ -foo -bar /}

by leriksen (Curate)
on Mar 02, 2004 at 00:55 UTC ( #333129=note: print w/ replies, xml ) Need Help??


in reply to Perl Idioms Explained - my ($foo, $bar) = @{shift(@_)}{qw/ -foo -bar /}

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;


Comment on Re: Perl Idioms Explained - my ($foo, $bar) = @{shift(@_)}{qw/ -foo -bar /}
Select or Download Code
(OT) Re: Re: Perl Idioms Explained - my ($foo, $bar) = @{shift(@_)}{qw/ -foo -bar /}
by rob_au (Abbot) on Mar 02, 2004 at 08:42 UTC

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (14)
As of 2014-12-18 20:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (61 votes), past polls