Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Comment on

( #3333=superdoc: print w/ replies, xml ) Need Help??

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.


In reply to Re: sub argument passing? (TIMTOWTDI) by temporal
in thread sub argument passing? (TIMTOWTDI) by temporal

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others surveying the Monastery: (5)
    As of 2014-09-19 02:55 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      How do you remember the number of days in each month?











      Results (129 votes), past polls