Sort the results array. The most fun way to do it is something like:
#!/usr/bin/perl -w use strict; use vars qw(@results); @results = ("Bean Burrito|0.69|5", "Seven-Layer Burrito|1.39|8", "Pintos -n- cheese|0.59|0", ); sub numerically_by_item { my($which)=@_; return sub { (split(/\|/,$a))[$which] <=> (split(/\|/,$b))[$which] } } sub alpha_by_item { my($which)=@_; return sub { (split(/\|/,$a))[$which] cmp (split(/\|/,$b))[$which] } } my $sortby; print "Sorted by price\n"; $sortby = numerically_by_item(1); print join("\n",sort $sortby @results); print "\n\n"; print "Sorted by name\n"; $sortby = alpha_by_item(0); print join("\n",sort $sortby @results); print "\n\n"; print "Sorted by messiness\n"; $sortby = numerically_by_item(2); print join("\n",sort $sortby @results); print "\n\n";
In reply to Re: How to place Search Results!!!
by sgifford
in thread How to place Search Results!!!
by ACJavascript
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |