rbi has asked for the wisdom of the Perl Monks concerning the following question:
use strict; my %hash = {a=>'A', b =>'B'}; my @array = [1,2,3]; my $scalar = 'This is a scalar'; 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); sub dummy { my %args = @_; my @a = @{$args{array}}; my %h = %{$args{hash}}; my $s = $args{scalar}; print "scalar is: $s\n", 'array is: ', join(',', @a),"\n", "hash is:\n", map "$_ => $h{$_}\n", keys %h; print "--------\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Passing hashes to subroutines
by cchampion (Curate) on Jun 08, 2004 at 08:59 UTC | |
|
Re: Passing hashes to subroutines
by blueAdept (Beadle) on Jun 08, 2004 at 14:17 UTC |