bjohn has asked for the wisdom of the Perl Monks concerning the following question:

This node falls below the community's threshold of quality. You may see it by logging in.

Replies are listed 'Best First'.
Re: min sub is not working
by toolic (Bishop) on Mar 23, 2011 at 15:26 UTC
    Update: The OP has made major changes since I posted this (only an un-indented sub was provided)...

    Is it "not working" because you're not calling the function, perhaps? It seems to work for me for one set of inputs:

    use warnings; #use strict; print min(qw(5 3 9 8)), "\n"; sub min { my (@num); @num = @_; $min = $num[0]; foreach $i (@num) { if ( $i < $min ) { $min = $i; } } return $min; } __END__ 3
      sry 4 my ignorance but i am new to perl. when i say not working i mean it is not outputting the $min value.
Re: sub min is not working
by wind (Priest) on Mar 23, 2011 at 16:41 UTC
    You need to capture the results returned from your subroutines
    my $av = aver(); my $min = min();
    Then just make sure to return a value in your min subroutine.
    sub min { my @num = @_; my $min; ... return $min; }

    Finally, you would be much better off if you had use strict at the beginning of your code.

    - Miller