in reply to Noob question
A ++ for the proposal using getcwd. An addition:
use strict; use warnings; use Cwd qw(getcwd); use Benchmark qw(:all); cmpthese(100000, { 'buildin' => sub { my $pwd = getcwd; }, 'backtick' => sub { my $pwd = `pwd`; chomp $pwd; }, });
Output on my computer:
$ perl am368.pl (warning: too few iterations for a reliable count) Rate backtick buildin backtick 4093/s -- -100% buildin 1666667/s 40617% --
Backtick operator spawns a subshell. This is expensive. So the rule of thumb should be: Before using backtick for gathering "simple" informations, check whether there is a Perl module providing this information.
Best regards
McA
|
|---|