Beefy Boxes and Bandwidth Generously Provided by pair Networks Frank
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Hash key string restrictions?[THANKS]

by Ojosh!ro (Beadle)
on Feb 09, 2007 at 20:17 UTC ( [id://599314]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Hash key string restrictions?

Thank you all very much. This is the answer I hoped for.
As to the purpose of the question:
I was experimenting with eval and wondered if I could put sub-references in a hash to prevent double evals.
(the mechanism behind it would check the existence of the to-be-evalled string and simply return a reference to the sub-ref in question if it existed and otherwise make a new pair )

I have no clue of whether such a mechanism already exists under perl's shiny bonnet.

  • Comment on Re: Hash key string restrictions?[THANKS]

Replies are listed 'Best First'.
Re^2: Hash key string restrictions?[THANKS]
by ikegami (Patriarch) on Feb 09, 2007 at 23:18 UTC
    Yup! Assuming the evaled code returns a code ref,
    my $code_ref = $code_cache{$code} ||= eval $code; die("Unable to compile and run code: $@\n)" if !$code_ref; $code_ref->();
      That was the basic idea,
      ( the ||= eval $code part would also be stored in the %code_cache )
        The statement I provided *does* store the result in %code_cache. Note the usage of ||= instead of ||.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://599314]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.