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


In reply to Re: malaga's hash/array/search problem by a
in thread malaga's hash/array/search problem by malaga

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.