Longer but quite possibly faster if it matters....
#!/usr/bin/perl use Inline 'C'; @ary = 1..10; print multiply( \@ary ); __DATA__ __C__ double multiply (SV * terms) { I32 numterms = 0; double res = 1.0; int i; if ((!SvROK(terms)) || (SvTYPE(SvRV(terms)) != SVt_PVAV) || ((numterms = av_len((AV *)SvRV(terms))) < 0)) { return 0; } for (i = 0; i <= numterms; i++) { res *= SvNV(* av_fetch((AV *)SvRV(terms), i, 0)); } return res; }
cheers
tachyon
In reply to Re: Multiplying together the numers in an array
by tachyon
in thread Multiplying together the numers in an array
by Cody Pendant
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |