> > im trying to sort out this sort routine: > > the sub by_number_of_citations works > > but if i try to make a sort alphabetically, my regex fails? > > how should it be done? > > > > # sting to match: <tr><td>1212</td><td>Cited > > Work</td><td>12</td><td>1232< /td><td>1999</td></tr> > > > > # sort routine > > # > > sub by_number_of_citations > > { > > $a =~ /\<td\>(.*?)\<\/td\>/; > > my $A = $1; > > $b =~ /\<td\>(.*?)\<\/td\>/; > > my $B = $1; > > > > $B <=> $A; > > }
May I suggest: (my $A = $a) =~ s/^<tr><td>(\d+)<\/td>/$1/; (my $B = $b) =~ s/^<tr><td>(\d+)<\/td>/$1/; > > # sort routine > > # > > sub alphabetically > > { > > $a =~ /^\<tr\>\<td\>\d+\<\/td\>\<td\>(.*)\<\/td\>/; > > my $A = $1; > > $b =~ /^\<tr\>\<td\>\d+\<\/td\>\<td\>(.*)\<\/td\>/; > > my $B = $1; > > > > $A cmp $B; > > } Again: (my $A = $a) =~ s/^<tr><td>\d+<\/td><td>(.*?)<\/td>/; (my $B = $b) =~ s/^<tr><td>\d+<\/td><td>(.*?)<\/td>/; But notice the (.*?) group... I think that might have been your problem. Let me know if that works, and if it doesn't, please post more data that you're comparing. > you haven't shown where you get the strings $a and $b which > you pass as > arguments to your subs. He's doing: sort by_number_of_citations @list sort alphabetically @list Which implicitly passes $a and $b into the custom sort subroutines. Neat, eh? :) Cheers, -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]