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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |