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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |