Sunil said:
Hi All,
I need to find the current working directory, Is there any alternative
to
use Cwd;
$pwd = cwd();
I am looking for a solution other than using system() or backtics
(``).
Thanks,
Sunil.
One way you could do it would be using the syscall function.
Unfortunately doing so seems to take about twice the time to run than
just using cwd.
-----------------Using syscall-----------------------
#!/usr/bin/perl
require 'syscall.ph';
#prepare the gunk string for up to 2048 chars
$gunk = pack('A2048', ' ');
#call getcwd, not sure if it would be off by one if I used 2048
#here so just to be safe I used 2047.
syscall(&SYS_getcwd, $gunk, 2047);
#trim off trailing whitespace
$gunk =~ s/\s+$//;
print "$gunk\n";
-----------------------------------------------------
time ./test.pl
/home/nekret/public_html
0.07user 0.00system 0:00.08elapsed 84%CPU (0avgtext+0avgdata 0maxresident)k
0inputs+0outputs (385major+206minor)pagefaults 0swaps
---------------Using cwd-----------------------------
#!/usr/bin/perl
use Cwd;
print cwd() . "\n";