Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 having an uproarious good time at the Monastery: (16)
As of 2014-08-01 17:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Who would be the most fun to work for?















    Results (36 votes), past polls