Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

RE: Out of a hole?

by ahunter (Monk)
on Jul 06, 2000 at 14:48 UTC ( #21287=note: print w/replies, xml ) Need Help??

in reply to Out of a hole?

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:

Warning: This really is a very evil hack. And it won't work on non-POSIXish systems...

require ''; use strict; use Carp; sub cwd () { my $buf = ' ' x 256; $! = 0; my $res = syscall(&SYS_getcwd, $buf, length($buf)) croak "getcwd: $!" if ($res == -1 && $! != 0); $buf =~ /\0.*$//; return $buf; }
This obviously requires the 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:
my $res = syscall(183, $s, length($s));
But it will almost certainly have radically different results on other operating systems!

Of course, if you are using Win32, it may not have getcwd, but it may have an equivalent.


Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://21287]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (5)
As of 2016-10-23 20:50 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (302 votes). Check out past polls.