Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

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?

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (7)
As of 2015-11-27 22:04 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (734 votes), past polls