Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: Sub hash param by reference

by perlfan (Curate)
on Jul 07, 2016 at 20:21 UTC ( #1167409=note: print w/replies, xml ) Need Help??


in reply to Sub hash param by reference

You can pass the whole hash by reference, then deref what you want using a hash slice if that's what you mean. Otherwise, what's the point if it's all by reference?

(tested on 5.22.1) See perldata for more info.
use strict; use warnings; use Data::Dumper; sub slice_by_ref { my $h = shift; my %subset = %$h{'foo', 'bar'}; print Data::Dumper::Dumper(\%subset); } my $h = {blonk => 2, foo => 3, squink => 5, bar => 8}; slice_by_ref($h);
OUTPUT:
$VAR1 = { 'foo' => 3, 'bar' => 8 };

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2020-05-27 07:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If programming languages were movie genres, Perl would be:















    Results (153 votes). Check out past polls.

    Notices?