in reply to retrieving information from a set of files
Perl is quite close to ideal for this sort of work.
My first tendency would be to use split; this means I get avoid playing games with substr (If I had to do that, I don't see much point is using Perl 8-)).
substr will work. The only issue, then, is how to determine which start/length pair to use for each file. This is easy (pseudo-code, not real code follows!):
Now, if your file names are not fixed, but use a predictable naming convention, the problem is slightly different, but still easy. Magic cookies would be similarly simple. If the files have column headers, you could parse that to find which field has account numbers. This is slightly trickier.my %layout = (file1 => 0, file2 => 0, ... file8 => 20, file9 ->10, file10 => 11); #note that Perl starts counting at zero, so 1 had to be subtracted fro +m the starting positions. # now, for each file, you could yank the acct number out like this: $acct = substr($line, $layout{$file_name}, 9); # where $file_name corresponds to file1, file2, etc, in %layout as app +ropriat
So, you code would have this sort of logic:
Again, my preference is generally to use split for simple delimited files; if you've got fields which include the pipe symbol (A|B|C|"this has a | pipe symbol but is one field"), you'll be better served by using a module, such as Text::CSV (I'm not endorsing that one; the only delimited files I've dealt with, I've controlled, so I knew, with certainty, that I wouldn't have fields where the delimiter should be ignored).
emc
At that time [1909] the chief engineer was almost always the chief test pilot as well. That had the fortunate result of eliminating poor engineering early in aviation.
—Igor Sikorsky, reported in AOPA Pilot magazine February 2003.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: retrieving information from a set of files
by Anonymous Monk on Oct 21, 2006 at 03:24 UTC | |
by graff (Chancellor) on Oct 21, 2006 at 05:32 UTC |