I have written a suit of 18 programs in Perl to process data in a folder called 'project/data'. During the development I realized that for each stage of the downstream analysis I'd better have intermediate data distributed into other folders for convenience within the same parent directory 'project', so I created folders such as 'project/test', 'project/regions' and 'project/report', data is sequentially processed in 'test' then in 'regions' then in 'report'.

Now, inside each one of those there is a Perl program that does something or the other with the data. For the sake of trace-ability I moved the programs into one location, 'project/PerlCode'. When these programs were written I have worked with absolute paths so I go passing the entire path qualifier for a program that reads or writes right from 'root' all the way to 'project' all the way to that specific folder where the program does its work.

Apparently, not the nicest of designs to be adopted, for better portability I will like to have this suite of programs create the downstream folders automatically and cohesively, easily done, but above all, the biggest/difficult part is, I want these programs to be oblivious to the directory structure and be contained in their own 'project' folder that regardless of which machine they run on they will just perform out of the box. Maybe this requirement is strongly suggestive of a modification from an absolute path dichotomy to a relative path one.

A potential candidate I have on the table is FindBin, yet it has issues that do with competitive calling (portentially solvable according to the docs). Another approach is to have a MasterScript.pl that calls each of these programs from 'PerlCode' folder, yet, each one of these programs should know which folder it gotta write or read into, how do I achieve this and avoid explicit calling of the entire path and make these programs aware of their immediate surrounding structures regardless of where in the directory tree the folder 'project' is placed ?.

Any tips, suggestions, alternative approaches and quick-fixes thereof are heartily welcome.



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...

In reply to Directory independent processing by biohisham

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • Outside of code tags, you may need to use entities for some characters:
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.