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

Re: Optionally include named arguments when constructing a new object

by jellisii2 (Hermit)
on Jun 02, 2014 at 13:00 UTC ( [id://1088258]=note: print w/replies, xml ) Need Help??


in reply to Optionally include named arguments when constructing a new object

If you're not completely locked in to your input parameters, Getopt::Long may be useful to you.
use strict; use warnings; use Getopt::Long; my %opts; GetOptions( 'address=s' => sub { $opts{$_[0]} = $_[1]; } 'user=s' => sub { $opts{$_[0]} = $_[1]; } 'pass=s' => sub { $opts{$_[0]} = $_[1]; } 'protocol=s' => sub { $opts{$_[0]} = $_[1]; } 'snmp_community=s' => sub { $opts{$_[0]} = $_[1]; } 'snmp_port=s' => sub { $opts{$_[0]} = $_[1]; } 'snmp_timeout=s' => sub { $opts{$_[0]} = $_[1]; } ... }
Getopt::Long can be set to carp/croak when your script doesn't have all the required items, which may come in handy as well.
  • Comment on Re: Optionally include named arguments when constructing a new object
  • Download Code

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (3)
As of 2024-04-25 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found