Limo has asked for the wisdom of the Perl Monks concerning the following question:
I have a program which takes a structured format file and reports back data contained in specified fields.
which produces the following output:eg: exfields.pl file.gz field1,field2,field3
I am trying to write a program which will merge 2 such files. file_1.gz and file_2.gz each contain different data associated with "steve", "jeff", ben", and I want to merge the output of both files, and display the end result to the user. output of: exfields.pl file_1.gz field1,field2:steve 37 ma jeff 35 ca ben 30 tn
output of: exfields.pl file_2.gz field1:steve 37 ma jeff 35 ca ben 30 tn
after both files are merged needs to become:steve guitar jeff bass ben drums
The first approach I considered (yes, I'm very new to Perl) with was creating 2 separate arrays and then joining them, only to realize that this would not accomplish my task. Tried all day, until now to:steve 37 ma guitar jeff 35 ca bass ben 30 tn drums
which extrapolates:merge.pl file1 field,field file2 field
pass it through a subroutine that would produce a hash containing:file1 field,field
then extrapolates:%hash_1 = steve => '37' AND 'ma' jeff => '35' AND 'ca' ben => '30' AND 'tn'
pass it through the same subroutine, which would produce a hash containing:file2 field
oh yeah, I am NOT trying to code this program as it appears; rather I am only trying to demonstrate what I am tring to do. I have the extrapolations that I referred to already coded. I also know how to produce %hash_2. My question is how could I code the subroutine to do what I am trying to do? Before that consideration, am I correct in thinking that the above examples of hashes will produce my desired result? I have read several references to "hashes with keys that contain multiple values", and "references to arrays", but I can't seem to use the examples effectively. Please help, while I still have hair on my head. .%hash_2 = steve => 'guitar' jeff => 'bass' ben => 'drums'
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Merging 2 Formatted Files
by moen (Hermit) on Sep 20, 2000 at 12:39 UTC | |
|
Re: Merging 2 Formatted Files
by fundflow (Chaplain) on Sep 20, 2000 at 17:04 UTC | |
|
Re: Merging 2 Formatted Files
by chromatic (Archbishop) on Sep 20, 2000 at 22:26 UTC | |
|
Re: Merging 2 Formatted Files
by Limo (Scribe) on Sep 20, 2000 at 22:52 UTC |