P
poopdeville
Hi everybody. I'm a bit new to Perl, and I'm having some trouble
getting it to do exactly what I'd like it to. Given an array of
numerals @data, I'm trying to generate a new array whose elements are
the fractions of minima over maxima of adjacent pairs in @data. Here's
my attempt (I've defined min and max elsewhere -- they compute the
minimum and maximum of arrays of arbitrary length, for generality)
@data = (1,2,4,8,16)
sub RR {
my $upper = $#_;
@LOF = min(($_[0], $_[1])) / max(($_[0], $_[1]));
for $i (1 .. $upper - 1) {
push @LOF, min($_[$i], $_[$i+1]) / max($_[$i], $_[$i+1]);
}
print @LOF, "\n";
}
RR(@data);
This is giving me the right *form* of answer, but instead of giving me
the .5.5.5.5 I expect, it's returning 0.510.50.25. Obviously, I've
misunderstood some convention. Anybody see what's wrong?
Thanks,
'cid 'ooh
getting it to do exactly what I'd like it to. Given an array of
numerals @data, I'm trying to generate a new array whose elements are
the fractions of minima over maxima of adjacent pairs in @data. Here's
my attempt (I've defined min and max elsewhere -- they compute the
minimum and maximum of arrays of arbitrary length, for generality)
@data = (1,2,4,8,16)
sub RR {
my $upper = $#_;
@LOF = min(($_[0], $_[1])) / max(($_[0], $_[1]));
for $i (1 .. $upper - 1) {
push @LOF, min($_[$i], $_[$i+1]) / max($_[$i], $_[$i+1]);
}
print @LOF, "\n";
}
RR(@data);
This is giving me the right *form* of answer, but instead of giving me
the .5.5.5.5 I expect, it's returning 0.510.50.25. Obviously, I've
misunderstood some convention. Anybody see what's wrong?
Thanks,
'cid 'ooh