Looping through files with perl -
OK I have 2 files, a file is a data that updates every 10 minutes while the other data is used first I went. What I am trying to do is take a line from the new file and loop through each line of the second file and see whether it matches one or not. If I do not want to use it, but if someone does not want to add to the string, then I want to add it to the string. I have done so far that it seems that there is no match at any time in the inquiry, even if there is one. Here is a sample of what I have and the data I am using with both files CHECKHAIL and USEDHAIL are two files
while (my $ toBeChecked = & lt; CHECKHAIL & gt;) {My $ = 0 found; Try useless, 0, 0 or die "$ 0: Explore: $!"; While (my $ hailCheck = & lt; USEDHAIL & gt;) {if ($ toBeChecked == $ hailCheck) {$ found + = 1; }} Printed USEDHAIL $ toBeChecked; If ($ mil == 0) {$ toEmail = $ toBeChecked; }} Print $ toEmail; Return; }
CHECKHAIL sample data
2226 175 2 NE Lawrence DEADWOOD SD 44.4-1033 (UNR) 2305 200 2 S SISKIYOU GREENVIEW CA 41.52 -122.9 inches The storage has been reported with Grenay in the south of the forest. (MFR) 2350 200 DANIELS E FLAXVILLE MT 48.8 -105.17 Golf Ball B Egg Shape Hail (GGW) 2350 175 5N Daniel Richland MT 48.89 -106.05 For Crop Crop (GGW)
USEDHAIL sample data
2226 175 NE Lawrence DEADWOOD SD 44.4 -103.7 (UNR) 2305 200 2 S. SISKIYOU GREENVIEW CA 41.52 -122.92 Inches with hail storm just south of GREENVIEW gave information. (MFR)
Why do not you just create a hash for the first (used) File?
Use strict; Use warnings; My% used file; Open USEDFILE, say '& lt;', '/ the / data / file / that / is / 10minutesold'; $ From the usefile {$ _} ++ while the & lt; USEDFILE & gt; Closed USEDFILE; While ($ toBeChecked = & lt; CHECKHAIL & gt;) {if ($ fromUsedFile {$ toBeChecked} defined) {# ... line is both new and old file} else {# ... line only in new file $ Is Tobeemailed = $ ToBeChecked; }}
Comments
Post a Comment