I am writing a subroutine that prints an array of non redundant elements from another array.
This code is inside my subroutine.
foreach (@old_table) { push(@new_table, $_) unless ($seen{$_}++); }
print "@new_table" . "\n";
Then i call my subroutine in a loop inside my main program, for the first iteration it is OK and my new table contains one occurrence of my old table.
But after that @new_table keeps elements from past iterations and the print result is false.
I tried emptying @new_table inside my subroutine like this
@new_table = ();
foreach (@old_table) { push(@new_table, $_) unless ($seen{$_}++); }
print "@new_table" . "\n";
But then my @new_table becomes empty in all iterations except for the first one.
What is the problem with this and how can i fix it ?