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

Re: Optimise the script

by Cristoforo (Deacon)
on Apr 01, 2011 at 01:13 UTC ( #896753=note: print w/ replies, xml ) Need Help??


in reply to Optimise the script

Using different modules, Time::Local and POSIX, is a direct way to compute today's date in UTC to compare to the dates in the file which are UTC. That avoids all the function calls in the loop you built, which really slow down the program.

#!/usr/bin/perl use strict; use warnings; use Time::Local qw/ timegm_nocheck /; use POSIX qw/ strftime /; my $n = 4; my ($d, $m, $y) = (gmtime)[3..5]; my $gmtime = strftime "%d/%b/%Y", gmtime timegm_nocheck 0,0,0, $d-$n, +$m, $y; $gmtime =~ s/^(?:0| )//; while(<DATA>){ print if /$gmtime\b/; }

But to impliment some of the time saving 'tricks' suggested by others in this thread would involve a while loop with more code.


Comment on Re: Optimise the script
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (10)
As of 2014-08-28 03:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (255 votes), past polls