Exactly. For those of you playing along at home, the way that you would do this is something like this:
############################## my @array = qw(one two three); my %hash = (first => 'Tim', last => 'Johnson', geek => 'yes'); my $scalar = "This is my string.\n"; myFunc(\@array,\%hash,$scalar); sub myFunc{ my($aRef,$hRef,$scalar) = @_; print "Here are the elements of \@aRef\n"; foreach(@{$aref}){ print " $_\n"; } print "\n"; print "Here are the keys and values of \%hash\n"; foreach(sort keys %{$hRef}){ print " $_ => $hRef->{$_}\n"; } print "\$scalar = \"$scalar\"\n"; } #################################### -----Original Message----- From: David Buddrige To: [EMAIL PROTECTED] Sent: 11/20/02 10:32 PM Subject: Re: passing an array and a hash to a subroutine. Hi all, I have figured out the solution to the problem below is to use an array of references to the various objects that I want to pass into the subroutine. thanks guys David. David Buddrige wrote: > Hi all, > > I want to write a subroutine that takes an array and a hash as input > parameters and then does some work on them. I can't seem to determine > how to do this however; it seems that with a subroutine, all you can > pass is a single array ( which appears as @_ ) to the subroutine. > > The program I am trying to write is below: > > > > #!/usr/bin/perl > > sub mysub > { > @my_array = @_; > %my_hash = %_; > > print "Print the array\n"; > > foreach (@my_array) > { > print "$_ \n"; > } > print "Now print the hash\n"; > > print $my_hash{"first"}; > print $my_hash{"second"}; > print $my_hash{"third"}; > } > > > > my %the_hash; > my @the_array; > > $the_array[0] = 5; > $the_array[1] = 43; > $the_array[2] = 78; > > $the_hash{"first"} = "number1\n"; > $the_hash{"second"} = "foo\n"; > $the_hash{"third"} = "abc\n"; > > mysub (@the_array,%the_hash); > > > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]