Dear Monks,
I have a list of elements (A, B, C, ...). They have a value :1, 2, 5 . These elements A, B, C can appear more than one time in the list.
I would like to supress the cases that appear more than one time in my list, and for those that appear more than one time, I would like that the values that appear in the left column are added
Here is the start file ("delay_${day}.csv")
1 A
0 B
3 C
0 A
2 C
5 A
3 E
1 E
Here is the file I would like to have in the end ("unique_delay_${day}.csv")
6 A
0 B
5 C
4 E
I have made a code, but it does not seem to work.
Could you tell me where did I go wrong ?
#!/usr/bin/perl
use strict;
use warnings;
##################################
## ARGUMENTS OF THE SCRIPT
##################################
# the argument due to be used is
# the ALL_FT file
#####################################
# do not forget the $ before the ARGV
#####################################
# the format of the ALL_FT file has to be : $date.ALL_FT (ex: 20060904
+.ALL_FT)
my $ALL_FT_file = "$ARGV[0]";
################# END OF THE DECLARATION OF THE ARGUMENTS
my $Current_Dir = `pwd`;
# print STDOUT "the current directory is $Current_Dir";
# name of the OUTFILE
# the day appears in the name of the OUTFILE
my $day = $ALL_FT_file;
# the following command is used to skip the .ALL_FT in the name of the
+ ALL_FT_file
# and thus to have the date
$day =~ s/.ALL_FT//;
# open the ALL_FT file
open(INFILE,"<delay_${day}.csv") or die "Can't open : delay_${day}.csv
+: $!";
# to open the file
# OUTFILE is the name of the HANDLE in this case
open (OUTFILE, ">unique_delay_${day}.csv") ;
# creation of a table
my @New_Table;
while (<INFILE>) {
# the lines are composed of elements separated by a point comma
my $Line = $_;
chomp($Line);
my @Elements = split(";", $Line);
push(@New_Table, $Elements[2]);
}
print @New_Table;
my %Hash = map { $_, 1 } @New_Table;
my @unique = keys %Hash;
close INFILE;
close OUTFILE;
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.