[Classiccity-pm] basic idiot question
Jeff Scarbrough
rail at uga.edu
Sat Oct 25 21:46:32 CDT 2003
At 06:51 PM 10/25/2003 -0600, I wrote:
>OK, between the suggestions you and Mark put forth, I think I'm on to
>something...
>
>So, now I've got one hash for each file, and I ~think~ I know how to get
>an array of keys...
I do...
>Next trick is to merge the arrays of keys, eliminate duplicates, and sort
>into numerical/chronological order. Then I can write a line consisting of
>the key (the DOY) and the lines of data from each file that match that
>key, or blank spaces if there is no data in one or more of the files.
>
>The part I need to learn now is how to do the cat |sort...back to Mr.
>Google's Laboratory...
Simple... I found a bit of code which ends up like this:
@key_list = ();
push @key_list, (keys %array_1);
push @key_list, (keys %array_2);
# Eliminate duplicate entries in key file and sort in ascending order
@key_dup = grep { ++$count{$_} < 2 } @key_list;
@key_sort = sort {$a <=> $b} @key_dup;
Eventually I will come to understand those two statements. I assume the
grep goes through and putts only one (<2) occurrrence of the items in
@key_list into @key_dup. I'm not sure yet why the sort is written as $a
<=> $b... but it works. I'm learning....
Anyway from there, I can write according to a format statement thusly:
foreach $key_sort(@key_sort) {
write OUTPUT_FILE;
}
where my format writes the following: $key_sort,
$array_1{$key_sort},$array_2{$key_sort};
Now, the only problem I have is when data does not exist for the key, I get
an "uninitialized" kind of error when I write...I need to include something
on the order of:
if ! $array_1{$key_sort} {
$array_1{$key_sort} = " ";
}
before I do the write... I'm sure the syntax there is faulty, but that's
the idea - same for each of the other arrays. Perhaps a nice single malt
will aid comprehension....
Progress!
Cheers,
Jeff
More information about the Classiccity-pm
mailing list