in reply to Re: Re: Re: Re: Re: Re: Problem creating a function
in thread Problem creating a function

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