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

my (%count, @isec, @diff, @union, @aonly) = ();
It is Initializing.
  • Comment on Re^2: Referencing in Function not working correctly.

Replies are listed 'Best First'.
Re^3: Referencing in Function not working correctly.
by chromatic (Archbishop) on Apr 02, 2010 at 19:12 UTC

    The assignment does nothing. Freshly-declared aggregates are empty regardless of any useless assignments.

Re^3: Referencing in Function not working correctly.
by jwkrahn (Abbot) on Apr 02, 2010 at 19:20 UTC

    What do you think it is initializing?

      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); }
      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?