Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Passing hashes to subroutines

by cchampion (Curate)
on Jun 08, 2004 at 08:59 UTC ( #362247=note: print w/replies, xml ) Need Help??


in reply to Passing hashes to subroutines

Your declaration for array and hash are wrong. If you use warnings you'll see why.

This modified code should do what you want:

#!/usr/bin/perl -w use strict; my %hash = (a=>'A', b =>'B'); # parens, not braces my @array = (1,2,3); # parens, not brakets my $scalar = 'This is a scalar'; # Pass an array REFERENCE dummy(array=>\@array, scalar=>$scalar, hash=>{a=>'A', b =>'B'}); dummy(array=>\@array, scalar=>$scalar, hash=>\%hash); my $hashref = \%hash; dummy(array=>\@array, scalar=>$scalar, hash=>$hashref);

HTH

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://362247]
help
Chatterbox?
Corion looks at TheDamians new modules. It seems he's written another Perl parser in a regexp and uses it for Keyword::Declare ...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (8)
As of 2017-06-23 07:52 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How many monitors do you use while coding?















    Results (536 votes). Check out past polls.