Member of the Programming Republic of Perl

Guy's Perl Q & A

Have a question about Perl? First check the updated Perl FAQ and the Perl documentation. If they don't solve your problem, send me an email and I'll do my best to answer your question. A summary of the question and answer may end up here.

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 6
Alternately, 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:
Need help with Perl? Send me your questions?