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

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?

Replies are listed 'Best First'.
Re^5: Referencing in Function not working correctly.
by jwkrahn (Abbot) on Apr 02, 2010 at 19:38 UTC

    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.

        :)

        perl -MData::Dumper -lwe 'my ( @x, @y, @z ) = ("z", "y", "z"); print D +umper(\(@x,@y,@z))' $VAR1 = [ 'z', 'y', 'z' ]; $VAR2 = []; $VAR3 = [];
        my (%Aseen, %Bseen, %count, @isec, @diff, @union, @aonly);

        They all are declared empty. No need to be explicit about it; and as the example above shows, that form of being explicit won't do what you might think anyway.

        When you have an aggregate (array or hash) in a list that variable will be assigned all the values.    So:

        my ( @x, @y, @z ) = ("z", "y", "z");

        Is exactly the same as:

        my @x = ("z", "y", "z"); my ( @y, @z );