Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: comparing list to 2 cells in array
by DamnDirtyApe (Curate) on Jul 25, 2002 at 23:55 UTC | |
by Anonymous Monk on Jul 26, 2002 at 19:21 UTC | |
by DamnDirtyApe (Curate) on Jul 26, 2002 at 19:32 UTC | |
by Anonymous Monk on Jul 26, 2002 at 20:12 UTC | |
by DamnDirtyApe (Curate) on Jul 26, 2002 at 20:25 UTC | |
| |
by fglock (Vicar) on Jul 26, 2002 at 20:12 UTC | |
|
Re: comparing list to 2 cells in array
by thelenm (Vicar) on Jul 25, 2002 at 22:10 UTC | |
|
Re: comparing list to 2 cells in array
by FamousLongAgo (Friar) on Jul 25, 2002 at 22:35 UTC | |
|
Re: comparing list to 2 cells in array
by DamnDirtyApe (Curate) on Jul 25, 2002 at 22:52 UTC |