You can always pinch the code out of the POSIX module
to do this (it uses the Cwd module under Win32, or
`pwd` under anything else). You could also do this
using an evil hack:
in reply to Out of a hole?
Warning: This really is a very evil hack. And it
won't work on non-POSIXish systems...
This obviously requires the syscall.ph header (and strict
and Carp, but you can get rid of them easily). If you
really don't want to use that either, you can find out
the value returned by SYS_getcwd. This goes beyond evil,
by the way, but under Linux (and probably nothing else),
this will work:
sub cwd ()
my $buf = ' ' x 256;
$! = 0;
my $res = syscall(&SYS_getcwd, $buf, length($buf))
croak "getcwd: $!" if ($res == -1 && $! != 0);
$buf =~ /\0.*$//;
But it will almost certainly have radically different results on other operating systems!
my $res = syscall(183, $s, length($s));
Of course, if you are using Win32, it may not have getcwd,
but it may have an equivalent.