Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

Re: working with relative paths

by steves (Curate)
on Oct 30, 2004 at 01:57 UTC ( #403952=note: print w/replies, xml ) Need Help??

in reply to working with relative paths

Relative paths should work with chdir, being relative to where you are when you run (not where the script is). Example from a Solaris Perl 5.8 system:

use strict; use Cwd; print "cwd [1] = ", cwd(), "\n"; chdir("/tmp"); print "cwd [2] = ", cwd(), "\n"; chdir("steve"); # relative! print "cwd [3] = ", cwd(), "\n";
cwd [1] = /export/home/foo cwd [2] = /tmp cwd [3] = /tmp/steve

Replies are listed 'Best First'.
Re^2: working with relative paths
by apotheon (Deacon) on Oct 30, 2004 at 02:19 UTC

    Maybe it "should" work (at least I think so), but the problem is that it doesn't. I'm beginning to wonder if it's some kind of system configuration issue. Is there any reason chdir() would work differently for a scalar variable than for hardcoded paths? Obviously, I'm trying to make a script that works for more than one filepath without having to rewrite the script every time.

    - apotheon
    CopyWrite Chad Perrin
      chdir has to work or I'll eat my hat, ;-) as it is one of the most fundamental functions. Perhaps if you posted a short but complete example, along with its actual output and the expected result, it would be easier to figure out what's going on.

      A couple of tricks that might help: use strict, warnings, and diagnostics; try chdir $direct or die $! to see if there is an error message.

        First, the code I just used:

        #!/usr/bin/perl -w use strict; my ($direct); chomp($direct = $ARGV[0]); shift @ARGV; chdir($direct) || die "failed to change to directory: $!"; opendir(WORKDIR,$direct) || die "failed to open directory: $!"; closedir(WORKDIR) || die "failed to close directory: $!";

        Next, the output:

        username@computer:~$ perl music failed to open directory: No such file or directory at li +ne 9. username@computer:~$
        - apotheon
        CopyWrite Chad Perrin

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://403952]
[tye]: 1) The python stack traces show you the names of variables, not the values of variables. Almost never informative.
[LanX]: do you have a py job now?
[tye]: Right now I have errors trying to fetch stuff from graphite. It says 'apps not ready, check startup logs'. I eventually find the startup logs and see 'no apps found'. Looking for fixes to this problem...
[LanX]: no idea ... ask py monks! ;-p
[tye]: it turns out that this can be caused by almost anything going wrong. If you want to know what caused the problem, you have to try to load each app by-hand to see what problems it is having, because none of those will be logged.
[tye]: No, I write more Perl than py at work. But I have to deal with plenty of py things.
[tye]: py monks would just be offended.
[Corion]: ;)
[Corion]: Hi tye btw ;)
[Corion]: I found plenty of not chatty enough logs with Perl too ... I'm slowly coming to appreciate Log::Log4perl resp. our homegrown alternative

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (7)
As of 2017-09-21 20:11 GMT
Find Nodes?
    Voting Booth?
    During the recent solar eclipse, I:

    Results (252 votes). Check out past polls.