On Monday, April 22, 2002, at 06:01 AM, [EMAIL PROTECTED] wrote:
> hi > > 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? > > > martin > > > > # 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; > } > > # 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; > } > you haven't shown where you get the strings $a and $b which you pass as arguments to your subs. also, you don't need to escape the angle brackets with backslash: '<' and '>'. i don't see anything wrong with the code as is, so i guess the problem is with setting up the arguments for the sub. Also, we don't see why you think it failed. maybe it didn't. I notice from the test string above you would be comparing 'Cited Work' with '1999'. you should be seeing that '1999' has a lower ascii value than 'Cited Work'. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]