Arg, I was hoping I wouldn't have to do that (not that I can't), but it
would be much easier in some calls. I have a variable like "$ToMailAddr".
Rather than setup a hash just to pass the value, it would be simpler for me
to say:
&mysub(%FromUser, {Address => $ToMailAddr});
where mysub is expecting two hashes, but really only uses the Address field
from the second. If it must be references, it must be references...
--Chuck
> -----Original Message-----
> From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]]
> Sent: Thursday, November 15, 2001 12:14 PM
> To: Tomasi, Chuck
> Cc: '[EMAIL PROTECTED]'
> Subject: Re: How to pass two hashes to a sub
>
>
> Unfortunately you HAVE to use references to pass more than
> one hash or more
> than one array for that matter ... perl flattens the list that are in
> arguments so it is impossible to tell where one list starts
> and the other
> begins etc. I dont get the setting up of temp hashes though
> ... what u could
> do is this
> sub mysub {
> my ($h1,$h2) = @_;
> #perform your magic on the hash reference instead
> }
>
> my %hash1 = (...
> my %hash2 = (...
>
> &mysub(\%hash1,\%hash2);
>
> On Thu, Nov 15, 2001 at 11:53:47AM -0600, Tomasi, Chuck
> shaped the electrons to read:
> > Perl 5.6.0
> > Sun Solaris 2.7
> >
> > I'd like to send two or more associative arrays (hashes) to
> a sub. It looks
> > like the first one makes it but the values of the second
> never get passed.
> > Am I doing something wrong or is there a better way to do
> this (I'm hoping
> > you don't say by reference or I'll have to setup a lot of
> temporary hashes
> > to pass one or two key/value pairs on second, third, and
> fourth args)
> >
> > --------------Code----------------------
> > #/usr/local/bin/perl -w
> >
> > use strict;
> >
> > sub phash
> > {
> > my (%hash1, %hash2) = @_;
> >
> > print "val1 = $hash1{'val1'}\n";
> > print "val2 = $hash2{'val2'}\n";
> > }
> >
> > my %h1 = ( val1 => 56 );
> > my %h2 = ( val2 => 45 );
> >
> > &phash(%h1, %h2);
> > ----------------output--------------------
> > $ perl mhash.pl
> > val1 = 56
> > val2 =
> >
> > --
> > 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]