[ABE.pm] Is this safe coding practice?

Ricardo SIGNES rjbs-perl-abe at lists.manxome.org
Fri Jun 1 16:48:37 PDT 2007

* Faber Fedor <faber at linuxnj.com> [2007-06-01T18:37:01]
> >I've got a func that returns the min and max values in an array:
> >
> >Nitpick:  subroutines never return arrays.  They return scalars or lists.  A
> >list is an immutable sequence of data, an array is a container that holds a
> >mutable sequence.
> (@MinY, @MaxY) = getMinMax(@foo)
> because Perl can't tell where to split the arrays I'm returning, right?


> >it correctly, and someday you will not make a mistake that you might have
> >otherwise made.
> I don't need that lecture, you whippersnapper! :-) it's one of my guiding
> principles and something I impress on my students.

Sorry, gramps!

> Then I don't grok the technique here.  If I modified my original code to use
> an array ref, the code would look like this:
> sub getMinMax {
>    my ($data) = @_ ;
>    my $stat = Statistics::Descriptive::Full->new();
>    $stat->add_data(@$data);
>    return ($stat->min(), $stat->max());
> }
> I don't see how to get/use a second parameter in the arrayref.

Not in the arrayref, but after it:

  sub getMinMax {
     my ($data, $arg) = @_ ;
     my $stat = Statistics::Descriptive::Full->new;

     $stat->pre_sorted(1) if $arg->{pre_sorted};

     return ($stat->min, $stat->max);


More information about the ABE-pm mailing list