Greetings Everyone,

I am a beginer with PERL and was wondering if anyone would be kind enough to help me learn the best way to fix my current sample view dir code that uses a simple drop down menu.

There is No 500 Error, just no change onclick with the listed folders at this time.

I only wish for the letter selected in my dropdown to be matched by this condition

if($_ =~ m/^[$FORM{'sortby'}]/){

By default i would like to display all folders and when selected [a] would only show [a] folders and so on... I am totally stumped on what I have done wrong?

I would be most greatful for your thoughts!

Thank you in advance~

Jim

note: The sortby_list.dat is simply a text file that contains a list of letters a thru z

############################################### #!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); $viewdirpath =""; # path $viewdirpath_only = ""; # url print "Content-type: text/html\n\n"; opendir DIR, "$viewdirpath"; @$_ = readdir DIR; closedir DIR; $count = 0; foreach $_ ( sort @$_ ) { $fitem_pathname = "$viewdirpath" . "/" . "$_"; if (-e $fitem_pathname) { if (-d $fitem_pathname) { unless ($_ eq "..") { unless ($_ eq ".") { $count++; } } } } } print "<body bgcolor=$bgcolor text=$text link=$link vlink=$vlink alink +=$alink>"; print "<b>Folders Listed In Directory - $count</b><br>"; print "sort by<br>"; print "<select name=\"sortby\" style=\"font-family: Arial; font-size: +10pt\" onChange=\"if(this.options[this.selectedIndex].value!=0) self. +location=this.options[this.selectedIndex].value\">"; open (INF,"sortby_list.dat"); @file=<INF>; close(INF); foreach $sortby (@file) { chomp($sortby); if ($FORM{'sortby'} eq $sortby) { print "<option value=\"$sortby\" SEL +ECTED>sortby</option>"; } else { print "<option value=\"$script?$sortby\">$sortby</option>"; } } print "</select>"; foreach $_ ( sort @$_ ) { $fitem_pathname = "$viewdirpath" . "/" . "$_"; if (-e $fitem_pathname) { if (-d $fitem_pathname) { unless ($_ eq "..") { unless ($_ eq ".") { if($_ =~ m/^[$FORM{'sortby'}]/){ @$_ = sort { $a cmp $b } @$_; print "<br><a href=$viewdirpath_only/$_>$_</a>"; } } } } } } #print "$footer"; }

Edit Petruchio Mon Jan 27 03:20:36 UTC 2003: Added markup


In reply to sorting a text file in PERL using a dropdown form by Anonymous Monk

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.