Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic

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?

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

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-11-28 19:42 GMT
Find Nodes?
    Voting Booth?

    What would be the most significant thing to happen if a rope (or wire) tied the Earth and the Moon together?

    Results (744 votes), past polls