I've got a feeling that I'm almost there, but I'm still missing something... Take a look how my code looks right now:
@sorted = sort {uc($a) cmp uc($b)} @results;
foreach $sorted (@sorted){
($field_1,$field_2,$field_3) = split(/\|/,$sorted);
print<<feach;
<tr>
<td bgcolor="#C0C0C0" colspan="2"><font face="Verdana, Arial, Helv
+etica, sans-serif" size="2"><a href="/relatorios/$user/$razao_social.
+data" target="_top">$razao_social</a></font></td>
</tr>
feach
}
It ALMOST worked, since I've got a result sorted like this (notice that I'm putting here the first letter of each field):
C
J
L
B
C
L
M
P
Q
R
S
T
Can you tell what I'm doing wrong?
Tx in advance,
Er Galvão Abbott
a.k.a. Lobo, DaWolf
Webdeveloper
| [reply] [d/l] |
Well, something is still amiss in the information you're providing. There's no sample dataset to see exactly what's going, so I made some up. The code sorts the data as I would expect, although the print statement makes no use of any of the $field_x variables that you have created.
I've commented out the print portion, since it produces no output relevant to your question. As you can see, the basic sort and printing for the variables you created works as one would expect.
I would assert that you are not using 'use strict' and -w in your script, which will cause you endless grief, the scorn of your ancestors, and a generally low karma value. Try adding them, clean the resulting errors up, and see if that helps a little.
#!/usr/local/bin/perl -w
use strict;
my @results = (qw(Z|a|b B|c|d H|e|f I|g|h K|i|j M|k|l E|m|n U|o|p P|q|
+r Q|s|t A|u|v));
my @sorted = sort {uc($a) cmp uc($b)} @results;
foreach my $sorted (@sorted)
{
my ($field_1, $field_2, $field_3) = split(/\|/,$sorted);
print "$field_1, $field_2, $field_3\n";
# my $user = 'arf';
# my $razao_social = 'spot';
# print<<feach;
# <tr>
# <td bgcolor="#C0C0C0" colspan="2">
# <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
# <a href="/relatorios/$user/$razao_social.data" target="_top
+">$razao_social</a>
# </font>
# </td>
# </tr>
#feach
}
A, u, v
B, c, d
E, m, n
H, e, f
I, g, h
K, i, j
M, k, l
P, q, r
Q, s, t
U, o, p
Z, a, b
--Chris
e-mail jcwren | [reply] [d/l] [select] |
jptxs:/home/jptxs $ vi sortExample
use strict;
while (my @sorted = <DATA>) {
print sort @sorted;
}
__END__
camel
llama
cheeta
owl
ant
butterfly
jptxs:/home/jptxs $ perl sortExample
ant
butterfly
camel
cheeta
llama
owl
Notice I didn't even have to include any arguements to sort alphabetically. Something to chew on as you work through this one : )
-- I'm a solipsist, and so is everyone else. (think about it) | [reply] [d/l] |