Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight

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

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1026277]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (6)
As of 2018-05-22 22:20 GMT
Find Nodes?
    Voting Booth?