Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
however, not all values in the list are guaranteed to be numbers. If the value is not a number, I want it left intact in the resulting list. Something like:sub round_all { my $interval = shift; my @result; foreach $value (@_) { my $quanta = int(($value + $interval/2) / $interval); push @result, $quanta * $interval; } @result; }
Is there a simple, non-ugly way to tell what is a number and what isn't?sub round_all { my $interval = shift; my @result; foreach $value (@_) { if(isnumber($value) { my $quanta = int(($value + $interval/2) / $interval); push @result, $quanta * $interval; } else { push @result, $value; } } @result; }
2006-05-08 Retitled by g0n, as per Monastery guidelines
Original title: 'isnumber() ??'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Is there an isnumber()?
by McDarren (Abbot) on May 06, 2006 at 03:06 UTC | |
|
Re: Is there an isnumber()?
by Zaxo (Archbishop) on May 06, 2006 at 03:09 UTC | |
|
Re: Is there an isnumber()?
by davidrw (Prior) on May 06, 2006 at 03:15 UTC |