One good example which comes to my mind is a helper subroutine I wrote for a test suite of one of my modules. Simply put that module has a subrotuine which given a set of input parameters can generate some output. In the test suite the helper subroutine wraps this call and compares the output with some file. If it matches the test is passed and if it doesn't it is not passed. The problem I had is that it in some cases it was ok for the output to vary slightly (for example it could contain current datatime or module version which change with time). So I had to use callback subroutine which cleaned up the output before comparing with the file.

Now compare:

# using OUT parameters run_test(params => \%params, filename => 't/foo/bar', cleanup => sub { $_[0] =~ s/foo/bar/ }); # not using OUT parameters run_test(params => \%params, filename => 't/foo/bar', cleanup => sub { my $var = shift; $var =~ s/foo/bar/; $var }) +;
To my taste first version is much cleaner.

As for my sarcasm. Probably it was wasted and I'd better to reword it to express myself better. The thing is that for any dynamical language like Perl runtime errors is a norm so I simply cannot accept argument that feature which might cause runtime error is a bad.

--
Ilya Martynov, ilya@iponweb.net
CTO IPonWEB (UK) Ltd
Quality Perl Programming and Unix Support UK managed @ offshore prices - http://www.iponweb.net
Personal website - http://martynov.org


In reply to Re: Re: Re: Re: Re: Re: Re: Problem creating a function by IlyaM
in thread Problem creating a function by Willman023

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!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • 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, details, 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, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            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.