Kristofer Wolff wrote:
>
> Hi all, I found out somthing that is really bad !
>
> i have a sub routine thats return a hash:
>
> ---------------------------------
> my %h = makeh();
> sub makeh
> {
> my %that;
> $that{eins} = "one";
> $that{zwei} = "two";
> $that{drei} = "three";
> return(%that);
> }
> --------------------------------
>
> fine ! it works for me since more than a year in a application. Today I
> change the script and add somthing that rewuires 2 hashes and i tryed this
>
> --------------------------------
> my (%h, %i) = makeh();
> sub makeh
> {
> my %that, %who;
> $that{eins} = "one";
> $that{zwei} = "two";
> $that{drei} = "three";
> $who{kris} = "wolff";
> $who{alex} = "seidel";
> return(%that, %who);
> }
> --------------------------------
>
> but now, i have EVERYTHING in %h and nothing in %i !!!!
> foreach(keys %h)
> {
> print "$_ - $h{$_}\n";
> }
>
> will show:
> eins - one
> kris - wolff
> zwei - two
> drei - three
> alex - seidel
>
> IS THIS A BUG OR AM I WRONG ???????
You're wrong camel breath. :)
Subroutines basically return an array (scalar being an array of 1 el).
So all of the two hashes are concatenated toegether into a large array
and returned. The first hash then picks up all of the array (since
there is nothing to stop it) and the second hash gets nothing. This
is normal operation. To get around it, you could return 2 hash refs
into two scalar vrbls or you could return the size of the first array
into a scalar and an array could pick up the rest of the two hashes,
and then you could rebuild the two hashes from that array (knowing the
size of the first hash). This is untested by me but should work.
--
,-/- __ _ _ $Bill Luebkert ICQ=14439852
(_/ / ) // // DBE Collectibles http://www.todbe.com/
/ ) /--< o // // Mailto:[EMAIL PROTECTED] http://dbecoll.webjump.com/
-/-' /___/_<_</_</_ http://www.freeyellow.com/members/dbecoll/
_______________________________________________
Perl-Win32-Web mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-web