in reply to array reference

You've got a couple of problems here that are interrelated.

First, each time you execute the statement, $hash{$s++} = \@final; you're using the same array @final...unless @final is a lexical that falls out of scope between each iteration.

Second is a consequence of the first... When you wipe out @final, you're obliterating the content of the array referred to by the hash element you just set.

You should use either (or both) lexical scoping to ensure that @final is a new instance each time you take a reference to it, and/or you should be using the anonymous array constructor to generate a reference to the data held in the array, rather than to the array itself. That means doing:

$hash{$s++} = [ @final ];

Instead of

$hash{$s++} = \@final;

You should definately actively seek to learn and understand lexical scoping as discussed in perlintro and perlsub, as well as the difference between taking a reference, and creating an anonymous array (see perlreftut and perlref, and perllol). I hope this helps...


Dave

Replies are listed 'Best First'.
Re^2: array reference
by prasadbabu (Prior) on Jan 16, 2005 at 10:36 UTC

    Thanks for all the suggestions given by gems. I have got the solution after changing into anonymous array reference.

    Prasad