On 12/20/2011 05:16 PM, Chris Stinemetz wrote:
I am having some trouble coming up with a solution for what I am
trying to accomplish.
Any advice is greatly appreciated.
...

*** input ***
csno=1
rfpi=1
vrp0=3423000
vrp1=3423000
trl=1700000
line=
low=
high=5

csno=1
rfpi=2
vrp0=3423000
vrp1=3423000
trl=1700000
line=
low=
high=5

csno=1
rfpi=3
vrp0=3423000
vrp1=3423000
trl=1700000
line=
low=
high=5
...
*** desired output ***
csno    rfpi    vrp0    vrp1    trl     line    low     high
1       1       3423000 3423000 1700000                 5
1       2       3423000 3423000 1700000                 5
1       3       3423000 3423000 1700000                 5

I'd suggest:

1. Declare an empty array of hashes data structure, to hold one record per array element.
2.  Declare a record counter (scalar) and initialize it to negative one.
3.  Use a while(<>) loop to read lines into $_:
    a.  chomp() the line to get rid of the trailing newline.
    b.  Jump to the next iteration if the line is empty.
c. Split the line on the equals sign and save the results into two variables, key and value. d. If the key is '>csno', get rid of the greater-than and increment the record counter. e. Use the record counter and key to save the value into the data structure. 4. Print the output. I've always used printf, field width/ type format specifiers, and a while loop, but Perl offers "formats" and this would be an ideal application to learn them.


HTH,

David

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to