The stupid question is the question not asked | |
PerlMonks |
Re: Complex Data Structuresby snafu (Chaplain) |
on Jun 19, 2002 at 16:22 UTC ( [id://175760]=note: print w/replies, xml ) | Need Help?? |
I sooo agree with everyone that stated the use of Data::Dumper. Don't leave vim without it! For me? Well, complex data structures have been something I've been getting to know intimately for this last project I've been working on. Mine haven't been nearly as daunting as others' here probably, but they have been challenging. I've been developing a script the purpose of which is to stage literally hundreds of thousands of files to a temporary location to be archived off to CD. The tough part was that these files are stored in locations that describe where we got the files (I work for a telco so by this I mean as far as which city they came from, what kind of carrier they are, what kind of billing we did on this file, etc). Additionally, there are files in those directories that were used to process the files we really need to archive off. Now, the most important part was that these files usually have datestamps embedded in the file names. Oh, but we can't have a universal naming scheme...nooo thus the date formats differ from file to file and indeed, there are even some files that have no datestamps in them at all. We stage the files based on where the files come from (or file type) and what the date of the file is. Alright, so my complex data structures come from two things. The first structure comes from the config file I invented for the script to read in order to know where to find the files, what kind of files they are, and where the files should go. That structure is a hash ref of a hash of hashes of arrays. The next structure I used is the actual file data such as filename, source, dest, date, and type which is only a hash ref of a hash of arrays. The data structure was not nearly as daunting as code I had to write to be able to keep the date formats for the destinations uniform. Since the dates in the filenames were not uniform, I had to devise a way to be able to read the dates in and match them up to a date format specified in the config file on a per RE basis. I then took that format and that date and reformatted the date to conform to a date mask we use when we create the directories for archiving. Geez, that took me a long time to work out. It works great in the context of the script but lacks (easy to break) if used from command line. Here is an example of the config file: Then part of the code where I am working through one of these structures is: Well, this is probably way more than you asked for but this project is way fresh on my mind and so I couldn't stop myself. :) To sum up I have come to really respect complex data structures. I have found that they can seriously shorten a task if they are used properly. I really can't come up with words to express how much I appreciate complex data structures. They are great!
_
_
_
_
_
_
_
_
_
_
In Section
Meditations
|
|