Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked

Re: passing subroutine args as a hash: why not?

by IOrdy (Friar)
on Jun 06, 2003 at 00:49 UTC ( #263566=note: print w/replies, xml ) Need Help??

in reply to passing subroutine args as a hash: why not?

I dont know if this is a good idea or not but I have taken to testing for a hash or hashref with something like the following:
#!/usr/bin/perl -w use strict; my %foo = ( a => 'b', b => 'c', ); print hash_or_hashref(%foo); print hash_or_hashref(\%foo); sub hash_or_hashref { die "missing options" unless $_[0]; # was it a hash or hashref passed. my $options; if (UNIVERSAL::isa($_[0], 'HASH')) { $options = shift; } else { $options = {@_}; } return $options->{a}; }

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2023-02-08 06:09 GMT
Find Nodes?
    Voting Booth?
    I prefer not to run the latest version of Perl because:

    Results (40 votes). Check out past polls.