No such thing as a small change PerlMonks

### Re^3: Finding the max()/min()

by cLive ;-) (Parson)
 on Nov 11, 2004 at 23:55 UTC ( #407227=note: print w/replies, xml ) Need Help??

in reply to Re^2: Finding the max()/min()
in thread Finding the max()/min()

Ahh, good point ;-)

Serves me right for trying to be creative on a Windows box sans Perl :)

cLive ;-)

Replies are listed 'Best First'.
Re^4: Finding the max()/min()
by dvo (Initiate) on Nov 05, 2011 at 08:33 UTC
This is the variant I found most straightforward to use:
```use List::Util qw[min max];

\$m = max(1,2);
[download]```
Re^4: Finding the max()/min()
by fnicholas (Initiate) on Jan 26, 2012 at 15:11 UTC
Here you go:

This is how one can find a maximum number in an array iteratively and recursively in Perl

```
#!/usr/bin/perl

my (@setOfnumbers);

@setOfnumbers = ( 9, 7, 90, 3, 8, 412, 67, 2, 45, 53, 1, 3,89 );

print "Finding maximum number iteratively ",
getMaximumNumber(@setOfnumbers) , "\n";
print "Finding maximum number recursively ",
findMaximumNumber(@setOfnumbers) , "\n";

#Finding maximum number iteratively
sub getMaximumNumber{
my (\$maximumNumber);
\$maximumNumber = @_[0];
foreach(@_){
if (\$_ > \$maximumNumber){
\$maximumNumber = \$_;
}
}
return \$maximumNumber;
}

#Finding maximum number recursively
sub findMaximumNumber{

my (\$maximumNumber);

if (@_ == 1){
\$maximumNumber = shift(@_);
return \$maximumNumber;
}
else{
\$maximumNumber = shift(@_);
return (findMaximumNumber(@_) > \$maximumNumber)
? findMaximumNumber(@_) : \$maximumNumber;
}

}

[download]```

Log In?
 Username: Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://407227]
help
Chatterbox?
 [GotToBTru]: \$aohoaoh->[0] is a hash reference, so \$aohoaoh->[0]->{ key1} would work [1nickt]: If 1nickt is the some guy, that's not what he said. [GotToBTru]: thepkd might not know about last hour of cb [1nickt]: my \$x = \$aohoaoh->[0]->{' foo'}->[0]->{'bar' }; should work [thepkd]: its not \$aohoaoh->[0]. its \$aohoaoh[0]->{'foo '}. Tried it. Its working. Thnaks [thepkd]: Hey 1nickt sorry man. What [GotToBTru]: a ref too far ;) [thepkd]: Yes this is my first time in cb. Trying to work my way around.

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (11)
As of 2016-12-06 13:41 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
On a regular basis, I'm most likely to spy upon:

Results (105 votes). Check out past polls.