in reply to malaga's hash/array/search problem
but to get a sortable hash you could:$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?
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:# use push on the off chance you've got multiple files w/ # the same sub date push @{$dates{$submitted_date}}, $FILE;
If the original submitted: date was in epoch time or whatever it is.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
is even uh, er, cooler. pointy hat, I'm sure, knows 3 better ways ;->.while ($term = shift @terms ) { print "$term"; print ", " if @terms; }
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 |