Wow, you guys are great! My Perl script is now only 10 lines, and works as I wanted it to. I'll need to add some error handling later, it outputs a -1 if the number has already been converted. A small thing that won't mess up my plans. (With regards to "simple padding of IP addresses")

My next script is importing an array, 4 deep, unspecified legnth. After doing this, I need to compare a different list to my hash table, and see if my number is between $ip and the second cell which is $ip2. I'm doing something wrong though. It's not working.

Thanks,
Carrie

#!/perl # open INFO, '<IPs.txt' or die; # Open the f +ile @line1 = <INFO> ; # Read it in +to an array close INFO; # Close the f +ile my %table; # Create a table open IN, '<source.txt' or die; # Name the file + with source addresses while (<IN>) { # Read file into table chomp; my($ip, $ip2, $country, $region) = split(' ',/,/,4); # Spli +t the IP address from the Country $table{$ip} = $region; } close IN; open(OUT, '>>conversion.txt') or die; foreach $line1 (@line1) # assign @l +ine1 to $line1, one at a time { if ($line1 >= $table{$ip} & $line1 <= $table{$ip2} ) { + # Compare the entry from log group to table print OUT $line1, ' ',$table{$line1},"\n" ; # Prints th +e line of the table } else {print OUT $line1;} } close OUT;

Edited 2002-07-25 by Ovid


In reply to comparing list to 2 cells in 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.