Perl - Prevent duplicate by checking if pattern already exist in opened file before writing -


I have a Perl script that manages to convert a specific file format to a CSV file that I later manage I can do

I need this script to be able to prevent duplicated lines from being generated:

  #get timetamp if ( (Rindex $ l, "ZZZZ,") & gt; - 1) {(my $ T1, my $ T2, my $ timestampmp1, my $ timestampm2) = partition (",", $ l); $ Timestamp = $ timestampp "". $ Timestamp1; } If (((($ ($ ($ ($ ($ ($, $ '', 'top' ''>> gt; -1) and (length ($ timestamp)>)) ((My @ top) = Split (",", $ l) ; My $ aecrire = $ serialnumber. $. $ HostnameT. "" $ Timestamp. "" $ Virtual_cpus. "". $ Logical_cpus. "" $ Smt_threads. "$. $ Top [1]; My $ i = 3; ############################################## ########################### While ($ i & lt; = $ # above) {$ aecrire = $ aecrire., '$ Head [$ I]. $ I = $ i + 1;} Print (FIC 2 $ AECER. "\ N");}  

My source file is FIC1 and destination file is FIC2, Unique The key is $ timestamp.

I see this script I prefer that the $ timestamp already exists in FIC1 or not, which has been opened at the beginning of the process), and if it does not exclude the line from writing FIC 2. If the $ timestamp is not present, then in general

Currently if the script is replayed on the already running file, then each row will be sorted by a timestamp and will be duplicated.

My goal is to repeat the event from time to time to be able to run the script on a file.

I'm fairly new to Perl, as far as I've seen it should be achieved using only% seen variables, but I could not get it successfully yet ...

Thank you very much in advance for any help: -)

A hash is describing

You will define a hash in your code

  my% looked = ();  

Then when you read a line - Before you decide to write it you can do something like this:

  # See that we saw Before we write it ($ $ {$ aecrire} eq 1 has been seen) {# nothing - skip the line} and {$ $ {$ aecrire} = 1; Print (FIC 2 $ AECER. "\ N"); }  

I did not check this code, but that is that jist


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -