Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^6: How to return values from a hash?

by perl-diddler (Hermit)
on Mar 30, 2013 at 14:52 UTC ( #1026277=note: print w/ replies, xml ) Need Help??


in reply to Re^5: How to return values from a hash?
in thread How to return values from a hash?

Um...._Var is the generic that is called for all of the 'named' vars...

I have a sub '_access_maker' that defines subs for each name in the field, those access routines all push on context and call Var.

If you wish to see it, it's fairly old code and probably could be optimized a bit...but it works...

sub varname ($) { substr $_[0], (1+rindex $_[0],':') } sub _access_maker { #{{xo{2 my $pkg = shift; #var in $_ { #TPe "(Dvam: %s::%s() )\xc2\x83",$pkg,$_; my $proc = '# line ' . __LINE__ . ' "' . __FILE__ . "\"\n" . ' { use warnings;use strict; package '.$pkg.'; sub '.$_.' (;$) { # create access routine for packa +ge::var $_=[$_,shift, Data::Vars::varname((caller 0)[3]), wantarray] +; goto &Data::Vars::_Var}; 1}'; eval $proc; $@ and die "Fatal error in $pkg\::Vars\::_access_maker?: $@\n"; } } ## end sub _access_maker }}}2

So _access_maker is called at compile time to define 'sub's for each of the the 'field' vars. So the code during execution is not _access_maker, but the sub...#create access routine for package::var You can see why I didn't bother including it... It's just a push of context and then a goto _Var


Comment on Re^6: How to return values from a hash?
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (11)
As of 2014-12-19 14:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (84 votes), past polls