Solved: sort regex trouble!
hi i finally got it to work. it was very simple ... _if_ you remember that its not td but td align=foo you are trying to match! martin On Wed, Apr 24, 2002 at 11:04:42AM -0400, David Gray wrote: May I suggest: (my $A = $a) =~ s/^trtd(\d+)\/td/$1/; (my $B = $b) =~ s/^trtd(\d+)\/td/$1/; That's not what he's doing. He's doing: my ($A) = $a =~ m{^trtd(\d+)/td}; my ($B) = $b =~ m{^trtd(\d+)/td}; Yours leaves everything after the /td tacked onto the end of $A; mine and his only store the number in $A. Argh, good catch. I usually do that kind of thing like: my $A = $1 if $a =~ m{^trtd(\d+)/td}; But I didn't that time :) Let us know if any of this fixes your problem, Martin... -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sort regex trouble!
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: trtd1212/tdtdCited Work/tdtd12/tdtd1232 /tdtd1999/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/^trtd(\d+)\/td/$1/; (my $B = $b) =~ s/^trtd(\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/^trtd\d+\/tdtd(.*?)\/td/; (my $B = $b) =~ s/^trtd\d+\/tdtd(.*?)\/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]
RE: sort regex trouble!
On Apr 24, David Gray said: 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/^trtd(\d+)\/td/$1/; (my $B = $b) =~ s/^trtd(\d+)\/td/$1/; That's not what he's doing. He's doing: my ($A) = $a =~ m{^trtd(\d+)/td}; my ($B) = $b =~ m{^trtd(\d+)/td}; Yours leaves everything after the /td tacked onto the end of $A; mine and his only store the number in $A. 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/^trtd\d+\/tdtd(.*?)\/td/; (my $B = $b) =~ s/^trtd\d+\/tdtd(.*?)\/td/; Again, see above. -- Jeff japhy Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for Regular Expressions in Perl published by Manning, in 2002 ** stu what does y/// stand for? tenderpuss why, yansliterate of course. [ I'm looking for programming work. If you like my work, let me know. ] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
RE: sort regex trouble!
May I suggest: (my $A = $a) =~ s/^trtd(\d+)\/td/$1/; (my $B = $b) =~ s/^trtd(\d+)\/td/$1/; That's not what he's doing. He's doing: my ($A) = $a =~ m{^trtd(\d+)/td}; my ($B) = $b =~ m{^trtd(\d+)/td}; Yours leaves everything after the /td tacked onto the end of $A; mine and his only store the number in $A. Argh, good catch. I usually do that kind of thing like: my $A = $1 if $a =~ m{^trtd(\d+)/td}; But I didn't that time :) Let us know if any of this fixes your problem, Martin... -dave -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
sort regex trouble!
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: trtd1212/tdtdCited Work/tdtd12/tdtd1232/tdtd1999/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; } -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]
Re: sort regex trouble!
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: trtd1212/tdtdCited Work/tdtd12/tdtd1232 /tdtd1999/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]