If you haven't, also check out my Perl Sample Code.
| Perl Questions and Answers |
|---|
Q: Perl's log function is actually ln (the natural log, log base
e). If I
want to work in base ten logs, what's the easiest way?
|
The Perl Cookbook has the best solution: use the log10 function provided
by the POSIX module. Here's how:
use POSIX qw(log10); my $number = log10(1000000); # $number should be 6Alternately, you can just divide by the proper base, e.g. my $number = log(1000000)/log(10); |
| Q: Is there a way to reference parts of an array in perl? Like say I want indices 3-15 of @array... |
Yes. You just put a range in the array element specifier. Here's an
example.
my @array=qw(0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20); my @subarray=@array[3..15];Here's an example using a reference to an array. my $ref=\@array; my @subarray=@$ref[3..15]; |
| Q: |