Hello
I have a list of IP addresses. In another file, I have another list of IP addresses, and the country from which they originate. I have keyed the array off the IP address.
What I need to do is take the IP in the first file, compare it to the second file, and then pull the associated country of origin from the second array. To make this easier, I am just pulling the entire line of the array, both IP and country.
I want to output this into a destination file.
This is what I've gotten so far. Am I doing this incorrectly?

#!/perl # $file1 = 'IPs.txt' ; # Name the file with IP addresses to be l +ooked up open(INFO, "<$file1" ) ; # Open the file @lines1 = <INFO> ; # Read it into an array close(INFO) ; # Close the file %file2 = 'Source.txt' ; # Name the file with source addresses open(INFO, "<%file2" ) ; # Open the file @lines2 = <INFO> ; # Read it into a two dimentional array close(INFO) ; # Close the file foreach $line1 (@lines1) # assign @lines1 to $line1, one at a time { foreach $line2 (@lines2) # assign @lines2 to $line2, one at a time { while $line1 != $line2 ; # Compare the entry from log gr +oup to source group { open(APPEND, ">>conversion.txt") ; print(APPEND "$line2" ; close(APPEND); } } }
Thank you
Carrie

updated by boo_radley : formatting, code tags.


In reply to Comparing 1 list and 1 array by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.