in reply to Re^2: Sorting Issue
in thread Sorting Issue
Update: suggestion about splitting is valid only if the result from database is "|"-separated, as cleverly pointed out here...
You had to say it immediately:
Note that, by default, putting @sorted_strings in double quotes will give you space-separated items. You can change the separator using the perlvar $":my @strings = split /\|/, $status;
I put the curly brackets in order to restrict the modification of the $" variable, making this modification "visible" to the print statement only.{ local $" = "|"; print "<br><font color=red>@sorted_strings</font><br>"; }
Anyway, I'd probably use a more flexible, metadata-based approach:
my %subst ( P => 'Posted', F => 'Posted', C => 'Posted', D => 'Posted', I => 'Posted', A => 'Accepted', N => 'New', R => 'Rejected', S => 'Save', X => 'Canceled', ); my @sorted_strings = sort map { $subst{$_} } split /\|/, $status; # The above line can be roughly expanded to the three lines below: # # my @status_letters = split /\|/, $status; # my @strings; # foreach (@status_letters) { # push @strings, $subst{$_} # } # my @sorted_strings = sort @strings;
Flavio
perl -ple'$_=reverse' <<<ti.xittelop@oivalf
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Sorting Issue
by Anonymous Monk on Jul 26, 2005 at 16:49 UTC | |
by polettix (Vicar) on Jul 26, 2005 at 16:59 UTC | |
by Anonymous Monk on Jul 26, 2005 at 17:35 UTC |