I have a little routine that is looking in a log file to see if an IP address is already in that log file:
my $current_time=time;
my @solog=();
open(OLOGS,"<$LOG_FILE");
my @logs=<OLOGS>;
close(OLOGS);
my $lcounter=@logs;
for ($lcounter; $lcounter >= 0; $lcounter--){
if ( $logs[$lcounter]=~^/$ENV{'REMOTE_ADDR'}/){
if ($HOURS == 0){
return 1;
}
@solog=split(/\t/,@logs[$lcounter]);
if ( ($solog[3] + ($HOURS * 3600)) > $current_time ){
return 1;
}
}
}
return 0;
In the code '$ENV{'REMOTE_ADDR'}' is 10.128.128.18
The log file contains 10.128.128.180 and it is finding a match. :-(
How do I modify the reg exp to make it not match to 10.128.128.180?
In the logfile the IP section is followed by a Tab, so I thought that adding
[:blank:] might do the trick, but I can't test it.
Any help would be much appreciated
P.S. Please don't berate me about bad/mal-formed IPs. These are internal IPs that my organisation chooses so I can't do anything about them.
Never knowingly obfuscated
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.