in reply to Directory independent processing

and make these programs aware of their immediate surrounding structures regardless of where in the directory tree the folder 'project' is placed ?.

"regardless" is a rather strong word; if your scripts should really find their project directory on their own, without any helping assumptions or config files, they'd have to recursively search all directories -- in general that's a very bad idea.

I know several approaches that some programs out there in the wild take (and often they take several of those in combination), listed in no particular order:

In the end, it all depends on what you want, and on the usualy work flow. Maybe you like some of the options I've listed.


Comment on Re: Directory independent processing
Re^2: Directory independent processing
by biohisham (Priest) on Oct 16, 2012 at 16:44 UTC
    The programs are in 'project/PerlCode' as well as the other folders 'test', 'data' and 'report', all of these are in 'project' so if I placed the directory 'project' anywhere it will carry with it the folder 'PerlCode' and the rest.

    Assuming that the current working directory is 'project' is a very plausible approach that I have partly implemented. I could probably hard-code the rest of the folders within CWD as they are.

    (Oct, 30th) UPDATE: I have implemented this through Cwd. Trying the other suggestions such as File::Spec threw errors that I could not solve. So through Cwd I basically could achieve creating new folders within 'project', moving files across these folders, and call other scripts that are saved in 'PerlCode' within 'project, it sounds fine and it performs the way I expect it to and ports well ...

    use Cwd; my $dir = getcwd; mkdir("$dir/output", 0777); open (my $fh, "<","$dir/data/file.txt") or die ("$!"); open(my $ofh, ">", $dir/output/outfile.txt) or die("$!"); while(my $line = <$fh>){ #do stuff such as process load into a data structure, regex #write to $ofh }



    David R. Gergen said "We know that second terms have historically been marred by hubris and by scandal." and I am a two y.o. monk today :D, June,12th, 2011...