Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: Hash key string restrictions?[THANKS]

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


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 10, 2007 at 04: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
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-04-26 06:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found