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
[Originally posted by grhoward]


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.

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