Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re: Counter that won't work with the IP Log

by mitd (Curate)
on Nov 15, 2001 at 14:08 UTC ( [id://125539]=note: print w/replies, xml ) Need Help??


in reply to Counter that won't work with the IP Log

No, No, my friend read Kanji first line -M is a FILE Operator It works on FILES not scalars. Also Kanji is a little confused in his use of localtime(time).

localtime(time) in an array context returns a list of time elements ($sec,$min ...), In your case you are using it in a scalar context in which case it returns a formatted time string ( Thu Nov 15 03:32:13 2001 ). If this is what you want your delta date calculations will probably need the assistance of a perl module like Date::Calc.

But there is an easier way that Kanji's example although not quite right, illustrates.

# code frag written in long hand for clarity (I hope) my $delta_day; my $now = time(); my $oldiptime = ---from your file -- (($now - $oldiptime) >= 86400) ? ($delta_day = 1) : ($delta_day = 0);
Your timestamps will now be in system time format but a simple three liner (hey using localtime() ) can coerce them back into human readable format.

Lastly you can vastly simplify your script by going to your favorite Perl reference and first reading about hashes and then reading about many options for 'tieing' external hashes. Here's a teaser.

# code fragment there's a use strict lusting above if ( exists ($IP_LIST{$ip} ) { go check delta day and stuff } else { # sdd it $IP_List{$ip} = $now; }

good luck

mitd-Made in the Dark
'Interactive! Paper tape is interactive!
If you don't believe me I can show you my paper cut scars!'

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://125539]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (8)
As of 2024-04-23 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found