Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: passing paramters to a sub

by rupesh (Hermit)
on Aug 30, 2005 at 05:51 UTC ( #487650=note: print w/ replies, xml ) Need Help??


in reply to passing paramters to a sub



Using references is a recommended way of passing hashes to subroutines.

my %hash = ( foo => "one", bar => "two", foobar => "three", ); my %values = func(\%hash); sub func { my $h_ref = shift; my %newhash; foreach my $key (sort keys %$h_ref) { print "$key => ", $h_ref->{$key}, "\n"; $newhash{$key}=$h_ref->{$key} if $key =~ /regexp/; } return \%newhash; }


Comment on Re: passing paramters to a sub
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (8)
As of 2015-07-28 05:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (252 votes), past polls