Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Perl saves the world - Film at 11

by dreadpiratepeter (Priest)
on Jul 22, 2009 at 16:57 UTC ( [id://782370]=perlmeditation: print w/replies, xml ) Need Help??

The other day I realized that I needed to implement a auto-expiring file cache to store some infrequently changing remote data.
I immediately went to CPAN and did a search on "cache expire" and looked at the first result Cache.
The example was clear and exactly what i needed to implement. Literally 5 minutes later I had my code working and passing tests.
I can think of no other language where the solving of a problem of this complexity would take so little time from realizing the need to implementation. Nor can I think of another language where I could implement the entire solution in 4 lines of my own code. Nor another language where I would have the confidence to use a third-party library without spending a lot of time looking through the implementation to verify its quality. With CPAN I inherently trust the quality of modules.
I know I'm preaching to the choir here, but I get so much joy out of Perl that sometime I need to sing out its praises

In case anyone is interested, here is the code:
use Cache::File; ... has _cache => (isa => 'Cache', is => 'rw', default => sub{ new Cache:: +File(cache_root => '/tmp/cacheroot')}); ... my $value = $self->_cache->get($key); unless ($value) { $value = do_operation(...); $self->_cache->set($key,'1 hour'); } return $value;


-pete
"Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."

Replies are listed 'Best First'.
Re: Perl saves the world - Film at 11
by CountZero (Bishop) on Jul 23, 2009 at 09:58 UTC
    With CPAN I inherently trust the quality of modules.
    That is a dangerous proposition. It may turn around and bite you at any moment.

    Although we all have to trust to some degree all the software (and hardware) we use, just blindly adding any odd module to a mission critical application is not advised!

    If the application is important enough, I would check the list of bugs (open and closed), CPAN::Forum, AnnoCPAN, CPAN ratings, ... and ask around in the Monastery if anyone has experience with this (new) module.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Perl saves the world - Film at 11
by Anonymous Monk on Jul 22, 2009 at 19:38 UTC

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlmeditation [id://782370]
Approved by SuicideJunkie
Front-paged by Arunbear
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2024-04-18 02:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found