Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://896753]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (6)
As of 2017-05-27 22:07 GMT
Find Nodes?
    Voting Booth?