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

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 'syscall.ph'; 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 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:
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.

Andrew.


Comment on RE: Out of a hole?
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (3)
As of 2014-09-21 02:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls