in reply to sub argument passing? (TIMTOWTDI)
Thanks guys, great suggestions, +1
Spent some time looking at Params::Check - seems perfect for what I want.
Aside from the fact that I'll have to define templates for all my subs, but I'm sure that I can come up with some way to dynamically create templates. Even still, it's easier than handwriting the logic myself.
On a related note, I was trying to sort using different comparison code blocks which are passed as args (within the hashref model above) to subs:
#! perl -w use strict; use Params::Check qw(check last_error); my $verbose = 1; my_func( { test_block => sub {$b cmp $a} } ); sub my_func { my $sort_function; my $tmpl = { test_block => { required => 1, defined => 1, default => sub {$a cmp $b}, strict_type => 1, store => \$sort_function} }; check($tmpl, shift, $verbose) or warn ('problem with check: ' . Params::Check::last_error +()); my @stuff = qw(foo bie bletch a z); @stuff = sort $sort_function @stuff; print join "\n", @stuff; }
Took a bit of tinkering to figure out how all that needed to be written to work properly so I thought it might be helpful to somebody if I posted it up here as well.
Thanks again, brothers.
Strange things are afoot at the Circle-K.
|
---|