The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

import-bot (20211) [Avatar] Offline
#1
[Originally posted by grhoward]

David,

I've thoroughly enjoyed your book and have recommended it to my associates.

Hope you don't mind me asking for some help with some code to solve a
particular problem similiar to the expample in Chapter 2. I'm trying to
address a problem when attributes(and corresponding values) change positions
in a record-oriented file, the number of attributes change, but certain vital
attributes always are present in the file.

In solution 3 of section 2.2.1, wouldn't the program example have been more
flexible if it had read in the fields from the file instead of declaring them
in the program (my @attrs = qw/artist.../smilie? In other words, if a
record-oriented file has a first line (or fourth line in this case in Fig 1.1)
that is a header of attribute names, couldn't we use each attribute name as
the key in the hash by reading them from the file? If so, would you mind
providing example code.

The following is an example of a record-oriented file.
attr1_name|attr2_name|attr3_name|attr4_name
record1_value1|record1_value2|record1_value3|record1_value4
record2_value1|record2_value2|record2_value3|record2_value4

The following is a simplistic example of the psuedo code:

Read header
Split attr_names from header and use them as keys in hash
Read all records and associate values with proper hash key

Regards,
Gary