| Store | Cart

Re: Passing Hash by reference - Basic pb.

From: $Bill Luebkert <d...@wgn.net>
Tue, 27 Jun 2000 11:54:14 -0700
Sylvain Aunay wrote:
> > Dear ALL> > Can someone explain to me what is wrong below : I'm trying> to pass HASH  'hash' BY REFERENCE to sub 'sub1'.> > Obviously, I didn't understand something with reference usage> (no output during sub1 execution).> > Thanks in advance> > --Sylvain>                  _______________________________> > sub sub1> {>     my ($hashref); $hashref = @_;

Try:
      my $hashref = shift;
or
      my $hashref = $_[0];

You're getting the array count into hashref which is not what you want.

>     print "\nsub1:\n";print %$hashref;>     print $hashref->{'K1'};> }> > #Main> {> #Populate> %hash=();> $hash{'K1'}="val1";> $hash{'K2'}="val2";> $hash{'K3'}="val3";> #> print "\nMAIN:\n";print %hash;> sub1 (\%hash);> }

-- 
  ,-/-  __      _  _         $Bill Luebkert   ICQ=14439852
 (_/   /  )    // //       DBE Collectibles   http://www.wgn.net/~dbe/
  / ) /--<  o // //      Mailto:d...@wgn.net   http://dbecoll.webjump.com/
-/-' /___/_<_</_</_    http://www.freeyellow.com/members/dbecoll/

Recent Messages in this Thread
Sylvain Aunay Jun 27, 2000 09:00 am
Joseph P. Discenza Jun 27, 2000 05:52 pm
$Bill Luebkert Jun 27, 2000 06:54 pm
Messages in this thread