bigip2000 has asked for the wisdom of the Perl Monks concerning the following question:
I have a script that runs a do statement as follows:
my @list = (@lines); foreach (@lines) { my @fields = split /,/; if ( $fields[2] eq '1' || $fields[2] eq '0' ) { @arr1 = do {"@fields[4]\n"}; my @out = uniq @arr1; print "this is @out"; } }
Even though I am using use List::MoreUtils qw(uniq); I never get the duplicates removed. What I get from the output of the @arr1 is
this is out XY-CAR-SHOP1_RADIATOR-PARTS this is out XY-CAR-SHOP1_RADIATOR-PARTS this is out QZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS this is out QZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS this is out QZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS this is out QZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS this is out QZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS this is out QZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS
Why don't the duplicates get removed? It should look like this: XY-CAR-SHOP1_RADIATOR-PARTS QZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS I have tried also the following:
my @list = (@lines); foreach (@lines) { my @fields = split /,/; if ( $fields[2] eq '1' || $fields[2] eq '0' ) { @arr1 = do {"@fields[4]\n"}; } } my @out = uniq @arr1; print "this is @out";
But that only causes one line to print out, the last one:
and missesQZ-CAR-STORE2-PRACTICAL_SNOWTIRE-02-X3-PARTS
can anyone help?XY-CAR-SHOP1_RADIATOR-PARTS
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: removing duplicates from do script
by 1nickt (Canon) on Feb 28, 2017 at 17:09 UTC | |
by bigip2000 (Initiate) on Mar 01, 2017 at 16:33 UTC | |
|
Re: removing duplicates from do script
by thanos1983 (Parson) on Feb 28, 2017 at 17:14 UTC |