Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Passing hashes to subroutines

by cchampion (Curate)
on Jun 08, 2004 at 08:59 UTC ( [id://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
Domain Nodelet?
Node Status?
node history
Node Type: note [id://362247]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (6)
As of 2024-03-19 02:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found