Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Sorting file with regex

by vinoth.ree (Monsignor)
on Jun 11, 2014 at 09:24 UTC ( [id://1089504]=note: print w/replies, xml ) Need Help??


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?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1089504]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-26 03:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found