in reply to suppress the elements that appear more than one time in a list

Build your hash inside your while loop, and get rid of @New_Table:

my %Hash; while (<INFILE>) { # the lines are composed of elements separated by a point comma <- +- it's a called a semicolon! chomp; my ( $k, $v )= split /;/; $Hash{$k} += $v; } my @unique = keys %Hash;

Replies are listed 'Best First'.
Re^2: suppress the elements that appear more than one time in a list
by steph_bow (Pilgrim) on Aug 01, 2007 at 12:54 UTC

    Thanks a lot FunkyMonk

    I have tried your method.

    However, I did not understand the line :$Hash{$k} += $v;
    I replaced with line :$Hash{$v} = $k;
    because I would like o have a unique list of the letters (not the numbers)
      It would perhaps be better from a maintenance point of view to leave the line

      $Hash{$k} += $v;

      as it is and change the split to reflect the fact that your value comes before the key on the line

      my ($v, $k) = split /;/;

      You still need to use += since you wish to accumulate the values.

      Cheers,

      JohnGG