<?xml version="1.0" encoding="windows-1252"?>
<node id="333129" title="Re: Perl Idioms Explained - my ($foo, $bar) = @{shift(@_)}{qw/ -foo -bar /}" created="2004-03-01 19:55:14" updated="2005-07-19 02:31:57">
<type id="11">
note</type>
<author id="189168">
leriksen</author>
<data>
<field name="doctext">
This may be more useful as a parser for simple command line arguments if you call it with &lt;code&gt;{@ARGV}&lt;/code&gt;&lt;p&gt;But there are [cpan://Getopt::Long|lots] of better ways to do that - this a very lightweight way.&lt;p&gt;
I've recently (last 3-4 months or so) been using named parameter lists for almost all my library code and also using [cpan://Params::Validate], so my idomatic (OO) code looks like&lt;br&gt;
&lt;code&gt;
package Chopper::Reed;

use Params::Validate qw/validate_with/;

sub psychotic {
 my $self = shift;

 my %params = validate_with(params =&gt; \@_,
                            spec   =&gt; {
                                       punch =&gt; 1,
                                       charm =&gt; {default =&gt; 'JOURNALIST',
                                                   regex = qr/^[CON]/},
                                       mutilate =&gt; 0,
                                      },
                           );

 $self-&gt;mutilate($params{$mutilate}) if $params{$mutilate};
 ...
}

...
1;

&lt;/code&gt;

&lt;i&gt;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."&lt;/i&gt;
&lt;div class="pmsig"&gt;
&lt;div class="pmsig-189168"&gt;
&lt;p&gt;+++++++++++++++++
&lt;br&gt;#!/usr/bin/perl
&lt;br&gt;use warnings;use strict;use brain;
&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
332886</field>
<field name="parent_node">
332886</field>
</data>
</node>
