jumk has asked for the wisdom of the Perl Monks concerning the following question:

Hi I have this small problem:
I have my script on my home dir , but i need to excute it to read files from a dir in the root
I am doing , the file i need my script to excute under is an upper level dir named logg so I am doing the following to move to that dir first:
chdir "/logg" or die " couldn't change dir ($!)";
but I could never change when I run the script which is under my home dir .. thanks for a hint

Title edit by tye

Replies are listed 'Best First'.
Re: chdir
by Enlil (Parson) on Jan 24, 2003 at 18:14 UTC
    Hello jumk,

    It is unnecessary and good practice not to put code tags around the whole text of your question. Only putting code tags around the code portion of your question is necessary. It makes it easier in case you have a lot of code for people to just d/l the code, and helps to visually seperate your code from plain text.

    As for your question why not do something like the following instead:

    my $active_directory = '/logg/'; my $working_file = $active_directory . "file_name"; open (FILE, $working_file) or die "Cannot open $working_file\n$!";
    where the file_name is the name of the file you are working with in that directory, that is unless you have a reason you absolutely have to chdir.

    -enlil

      I think it's quite alright (maybe he likes the way fixed font looks), as long as there are newlines between code and text.
Re: chdir fails
by vek (Prior) on Jan 24, 2003 at 18:22 UTC
    jumk - I would probably do something like Enlil suggests and not chdir at all. That having been said, let's try and troubleshoot your existing code. First of all what is the error message in $!? Does the /logg directory exist? Do you have permission to cd to it?

    -- vek --