in reply to Sorting file with regex

Hi,

By assuming that the last name comes after the }, I have written the code here, which sorts based on the last name.

use strict; use warnings; use Data::Dumper; my @lines; while (<DATA>) { chomp; $_ =~/}(\w+)/; push @lines, [$1,$_]; } @lines = sort { $a->[0] cmp $b->[0] } @lines; print Dumper \@lines; __DATA__ '\bibitem{all99}Allison P.D.' '\bibitem{al200}Vinoth B.D.' '\bibitem{al200}Ana A.D.'

All is well

Replies are listed 'Best First'.
Re^2: Sorting file with regex
by AnomalousMonk (Archbishop) on Jun 11, 2014 at 10:00 UTC

    Further to davido's point above, how does this handle names like Van den Berghe or O'Boyle?