in reply to Re: Re: Get biggest value from array
in thread Get biggest value from array

Hi,

If @array=(-3, -4, -2); then this code will fail.

The $max variable should be initialised by shift()ing a value from @array.
A small change would be required to the regex to allow negative numbers too. So we have
#!/usr/bin/perl -w use strict; my @array=(-3,-4,-2); my $max=shift @array ; foreach (@array) { if (/^-?\d+$/) { $max=$_ if ($_>$max) } } print $max;
cheers

thinker