DarrenSol has asked for the wisdom of the Perl Monks concerning the following question:
I've run across an obstacle in Perl that I didn't expect. Reading through the module tutorial, it appears that this obstacle is intended. Seems odd to me, since the Perl motto is TMTOWTDI.
The way I'd like to do it seems to me the most logical, but Perl, apparently, says I can't do it this way :( Mayhap my gray-matter processing unit is defective...
This is the problem : I have a set directory tree I'm working with, and a number scripts that process the files.
Seems to me the most straight-forward way to handle this would be to load the directory structure, or specific branches of it, into arrays.
I'd like to make these arrays, and their contents, available to a script by coding them in a module, as I've done with hard-coded variables. Is this something that Perl doesn't want me to do ?
I've considered either script to traverse the directory tree, or callable sub-routines, but these seem like overkill for a set directory tree. Either one seem to me to be "making an easy thing hard" :P
An example, with a subset of the directory tree:
The initial files are downloaded to the DownLoad folder. These are update files for data sets I've already started.
The files in the DownLoad folder are moved to the appropriate "raw" folder, retained as an archive.
The "raw" folder files, which are updates, are appended to the existing data from the files in the "processed" folders. The merged data overwrites the files in the "processed" folders.
The "processed" files are analyzed, with summary reports placed in the "analysis" folders.
Sample tree structure:
\DownLoad (top folder, initial downloaded files)
\DownLoad\Weekly\raw (downloaded Weekly files moved here)
\DownLoad\Weekly\processed (merged files)
\DownLoad\Weekly\analysis (file summary reports)
\DownLoad\Daily\raw (downloaded Daily files moved here)
\DownLoad\Daily\processed (merged files)
\DownLoad\Daily\analysis (file summary reports)
I'm writing scripts to process files in those directories. Then, for example:
foreach $RawFileName ( $DownLoadFolder )
{ distribution script, files moved to "raw" folders }
foreach $AppendFileName ( @WeeklyDirTreeArray ) { (script) }
or
foreach $AnalyzeFileName ( @DailyDirTreeArray ) { (script) }
This works, but I'm only able to do this by pasting the array declaration and initialization code in each script. Seems cumbersome and kludgy. If I change or add to the tree in the future, I'll have to propagate the changes manually to each script - more kludgy copy-and-paste.
Unlike hard-coded variables which most or all of the scripts use, I can't declare the arrays in a module and fill them - which seems to me the logical way to handle hard-coded arrays.
Writing script to traverse the directory tree would work, but seems like unnecessary overhead for set-in-place traversing routines. And the traversing code would be copied-and-pasted into each script, which still seems kludgy. Likewise if I change or add to the directory - manual editing of the traverse code in each script.
Creating a callable sub-routine in a module, which would declare and initialize the arrays, would work, but seems to be unnecessarily complicated overhead for a basic programming problem. Again, "making an easy thing hard", which just don't seem very Perl-like :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Fill an array in a module ?
by RonW (Parson) on Sep 13, 2014 at 21:54 UTC | |
by AnomalousMonk (Archbishop) on Sep 14, 2014 at 01:20 UTC | |
by Anonymous Monk on Sep 14, 2014 at 05:18 UTC | |
by dsheroh (Monsignor) on Sep 14, 2014 at 07:59 UTC | |
by RonW (Parson) on Sep 15, 2014 at 16:39 UTC | |
by DarrenSol (Acolyte) on Sep 17, 2014 at 17:15 UTC | |
by DarrenSol (Acolyte) on Sep 17, 2014 at 17:06 UTC | |
by RonW (Parson) on Sep 17, 2014 at 17:34 UTC | |
|
Re: Fill an array in a module ?
by einhverfr (Friar) on Sep 14, 2014 at 02:24 UTC | |
by DarrenSol (Acolyte) on Sep 17, 2014 at 17:27 UTC | |
|
Re: Fill an array in a module ?
by DarrenSol (Acolyte) on Sep 13, 2014 at 18:01 UTC |