I have a perl script that manage conversion of a specific file format into csv files i can manage later.
I need this script to be able to prevent generating duplicated lines:
#get timetamp
if ((rindex $l,"ZZZZ,") > -1) {
(my $t1, my $t2, my $timestamptmp1, my $timestamptmp2) = split(",",$l);
$timestamp = $timestamptmp2." ".$timestamptmp1;
}
if (((rindex $l,"TOP,") > -1) && (length($timestamp) > 0)) {
(my @top) = split(",",$l);
my $aecrire = $SerialNumber.",".$hostnameT.",".$timestamp.",".$virtual_cpus.",".$logical_cpus.",".$smt_threads.",".$top[1];
my $i = 3;###########################################################################
while ($i <= $#top) {
$aecrire = $aecrire.','.$top[$i];
$i = $i + 1;
}
print (FIC2 $aecrire."\n");
}
My source file is FIC1 and destination file FIC2, the uniq key is $timestamp.
I want the script to check if $timestamp already exist in FIC1 (which is opened at begin of process), and if it does exclude the line from being writing to FIC2.
if $timestamp is not present, then write as normal.
Currently if a rerun the script over an already proceeded file, each line will be sorted by the timestamp and duplicated.
My goal is to be able to run this script periodically over a file without duplicating events.
I'm quite new to perl, as far as i've seen this should be achieve simply using the %seen variable within the while, but i could not yet achieve it successfully...
Thank you very much in advance for any help :-)