develooper Front page | perl.perl5.porters | Postings from July 2008

Every.pm on CPAN

Thread Next
From:
Ted Zlatanov
Date:
July 18, 2008 07:05
Subject:
Every.pm on CPAN
Message ID:
86sku7migp.fsf@lifelogs.com
I put a module Every.pm on CPAN, which lets you do

print "hi" if every(5);

which will print "hi" once every 5 times it's called.  There's a form
for seconds elapsed as well, which will run if N seconds have elapsed.

(it came to be with help from c.l.p.misc regulars, it's not just mine)

I wonder if:

1) there's any chance of including it in the core in some form; I think
it's really useful and the common (if $i % 5 == 0) format has lots of
shortcomings;

2) there's a way to know not just the line, but also the character
position of a function call, so we can do

if (every(5) || every(6)) {}

without resorting to shenanigans like using \5 and \6 or passing a
special identifier in addition to the number.

Thanks
Ted


Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About