I'm writing a simple script to make two copies of a file and put into a specific directory. As you can see in the code I'm copying from a file in the /ABC/ directory and putting them in /ABC/old/ directory. However my perl script is located in the directory /ABC/perlscript/ and when I run the script it tells me file doesn't exist at the location so my question is how do i access the contents of the folder higher up in the folder hierarchy than my script itself?

Although possible, it is very uncommon to require that the user does a cd into the script directory, just to execute the script. Usually the cd is done (if it is necessary at all) to the directory which contains the data to be processed.

I don't want to have the script in the PATH, I need it in its own directory.

I didn't suggest to move your script to a different location. I proposed to extend your PATH - or do use a full path to access your script.

Quote

I thought about using cd within the script to access the data but am unsure how to do that.

You could do this (see perldoc Cwd), but it's not a good idea: It is - at least in your example - pointless to use *relative* pathes in your scripts AND then chdir to the appropriate location, only to make the relpathes work. In this case, you could have accessed your data by abspath in the first place.

Why don't you like the idea to write out the path when accessing your script?

I've resolved the issue (via everyones help on here) by just referencing the absolute path/directory.

I misunderstood what you meant, I thought you were saying to move the script to a different directory rather than calling it from a different directory by writing out the location of it. That would work fine I assume however I've resolved my issue and my script is now functioning properly.

Yes, but as a matter of reliability and security, even when a script is in my current directory, I prefer to type: "./my_script.pl", rather than simply "my_script.pl", just to make sure that I know for sure which version is being used (rather than relying on the PATH, which may sometimes create problems). This is not paranoia, but the voice of experience: I have been bitten too often by the error of not executing the program version I thought I was using.

In the case ./my_script.pl you are right, of course (though I, being lazy, and lucky enough not being bitten yet, still prefer less typing), but in the case of the example you gave (./some_directory/my_script.pl), PATH searching isn't done anyway. But I agree: If you always prepend your relpathes by ./, you don't have to think about this difference, and you are always on the safe side.

With respect to safety, I'm a bad guy anyway, because I have "." in my PATH.... ;-)