[Purdue-pm] Reminder

Phillip San Miguel pmiguel at purdue.edu
Tue Jan 23 09:42:39 PST 2007

David Jacoby wrote:
> Tuesday night is Social Meeting time! 7pm at Cafe Royal on
> fabulous Chauncey Hill. See you there!
I'll be there.
By the way. I should probably present this at the next technical 
meeting, but I'll probably have forgotten it by now. Kewl way to pack a 
white space delimited list with a single header line containing column 

For example, data looks like:
Row Column  spot   call
A   1   1   +
A   1   2   +
A   1   3   -
A   1   4   +
A   1   5   +
A   1   6   -

#read first (header) line and parse column names
my @col_names;
while (<>){
    #This allows the first row to set the field order
    @col_names   = split;
my @array_of_hash_records
#Now read all the rest of the lines
while (<>){
    my %record;     #hash to parse fields
    #assign to hash slice. Column headers are keys.
    @record{@col_names} = split;    #kewl! column names become hash keys
    push @array_of_hash_records, \%record   #save each record to data 

Weird things here are the "hash slice". Which I think means:


is the same as


and, instead of writing out the keys, you can just use an array:

@array=('a','b','d'); @hash{@array}

is the same as



More information about the Purdue-pm mailing list