in reply to Re^2: Referencing in Function not working correctly.
in thread Referencing in Function not working correctly.

What do you think it is initializing?

  • Comment on Re^3: Referencing in Function not working correctly.

Replies are listed 'Best First'.
Re^4: Referencing in Function not working correctly.
by mr_p (Scribe) on Apr 02, 2010 at 20:01 UTC
    OK, I got a working version. I things around as you suggested (hopefully). Now I want to make sure it is as efficient as possible. Can you please look at this code and see if it can get anymore efficient. or should I open a new thread?
    sub deDuppedArray { my ($a_ref, $b_ref, $my_bonly, $my_isec_plus_bonly) = @_; # refere +nce my (%Aseen, %Bseen, %count, @isec, @diff, @union, @aonly) = (); @Aseen{@$a_ref} = (); # lookup table @Bseen{@$b_ref} = (); # lookup table foreach my $e (@$a_ref, @$b_ref) { $count{$e}++ } # put all items +in hash table foreach my $e (keys %count) { # interate over each key of hash table push(@union, $e); # keys of hash table = union if ($count{$e} == 2) { push @isec, $e; # seen more than once = intersection } else { push(@aonly, $e) unless exists $Bseen{$e}; # seen once + f +rom A = Aonly push(@$my_bonly, $e) unless exists $Aseen{$e}; # seen once + + from A = Aonly } } @$my_isec_plus_bonly = ( @isec, @$my_bonly); }
Re^4: Referencing in Function not working correctly.
by mr_p (Scribe) on Apr 02, 2010 at 19:26 UTC
    my @x = ("z", "y", "z"); @x = ();

    Doesn't the @x get initialize here? If I want to reuse @x what do I do to initialize, is there another way?

      Yes @x gets initialized there, but ("z", "y", "z") is different than (), and my @x is different than my ( @x, @y, @z ).

      What do you think my ( @x, @y, @z ) = ("z", "y", "z"); does?

        I am sorry I have no idea what that does. Please explain. My guess is @x[0]=z, @y[0]=y and @z[0]=z.

        When I had the below statement, I was trying to create and initialize values of all variables.

        my (%Aseen, %Bseen, %count, @isec, @diff, @union, @aonly) = ();

        Please let me know what I'm doing wrong.

        Thanks for your help.