Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re: sub argument passing? (TIMTOWTDI)

by temporal (Pilgrim)
on Sep 13, 2012 at 21:47 UTC ( #993586=note: print w/ replies, xml ) Need Help??


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.


Comment on Re: sub argument passing? (TIMTOWTDI)
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (6)
As of 2015-07-05 06:48 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls