in reply to malaga's hash/array/search problem

Sorry if we've left you hanging. The above posts are, of course, spot on - you've lots to tidy up if you want to get -w/use strict to work and that'll help. But the sorting problem: Well, seems like you could do:
$title = $1 if $LINES[0] =~ /title: (.*)$/i; # though $[ is better than zero $submitted_date = $1 if $LINES[15] =~ /submitted: (.*)$/i; # But how do you know its line 16?
but to get a sortable hash you could:
# use push on the off chance you've got multiple files w/ # the same sub date push @{$dates{$submitted_date}}, $FILE;
the trick here is; in the dates hash, use the submitted_date/string3 key but make it ref an array. You can then push on as many file names as share the same submitted date and then pop them off later when your sorting through the dates hash. Sort the dates keys and then pop the arrays to get back file names. Trust me, it works! so when you get down to:
foreach $key (keys %include) { if ($include{$key} eq 'yes') { print "<li><a href=\"passtest.cgi?$key\">$titles{key}<br>$titles2 +{$key}<br></a><br><br>\n"; } } # try instead: foreach my $date ( sort keys %dates ) { foreach $key ( @{$dates{$date}} ) { if ($include{$key} eq 'yes') { print "<li><a href=\"passtest.cgi?$key\">$titles{key}<br>$titles +2{$key}<br></a><br><br>\n"; } # if include eq yes } # foreach key @dates } # foreach date dates
If the original submitted: date was in epoch time or whatever it is.
More cleanup: you probably want to put a $title2{$FILE} = $string3; in the "if ( $string =~ /<title ... " block or rather, take it out of the else and always "$title2{$FILE} = $string3;" Though now now you can (inside the foreach loops)
$pretty_date = scalar localtime $date;
and replace $titles2{$key} w/ $pretty_date and skip %titles2 altogether.
You can probably skip the '$include{$FILE} = "no";' part, as you never use these files, why put them in %include at all. That'll save you the 'eq "yes"' test later. Also 'print ", " unless $i == @terms' is a bit more perlish, though if you used:
while ($term = shift @terms ) { print "$term"; print ", " if @terms; }
is even uh, er, cooler. pointy hat, I'm sure, knows 3 better ways ;->.
HTH

a

Replies are listed 'Best First'.
Re: Re: malaga's hash/array/search problem
by malaga (Pilgrim) on Jan 25, 2001 at 07:16 UTC
    a, thank you. i haven't learned how to use this site real well yet, so didn't get my thanks to you. i appreciate your help. the sort problem was interrupted. now i'm trying to make sense of this site so i can start writing for it. it's a web of cgi's - nothing static. later, malaga