Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Advanced Bubble Sort

by tybalt89 (Monsignor)
on Oct 13, 2016 at 21:30 UTC ( [id://1173962]=note: print w/replies, xml ) Need Help??


in reply to Advanced Bubble Sort

#!/usr/bin/perl -l # http://perlmonks.org/?node_id=1173958 use strict; use warnings; my @data = <DATA>; my $numbers = ''; $numbers |= $_ for "@data" =~ /\d+/g; my $length = length $numbers; my %packages; @packages{ /^([\w-]+)/ } = $_ for map $_->[0], sort { $a->[1] cmp $b->[1] } map [ $_, s/\d+/ sprintf "%0${length}d", $& /ger ], @data; print sort values %packages; __DATA__ samba-common-libs-4.2.10-6.2.el7_2.x86_64 samba-common-libs-4.2.10-8.el7_2.x86_64 samba-common-libs-4.2.12-7.el7_2.x86_64 samba-common-libs-4.2.10-6.el7_2.x86_64 samba-common-libs-4.2.10-3.el7_2.x86_64 xyz-libs-4.2.10-7.el7_2.x86_64 xyz-libs-4.2.12-7.el7_2.x86_64 xyz-libs-4.2.13-7.el7_2.x86_64 xyz-libs-4.2.11-7.el7_2.x86_64 abc-4.2.11-7.el7_2.x86_64 abc-4.2.11-8.el7_2.x86_64 abc-4.2.11-6.el7_2.x86_64

prints:

abc-4.2.11-8.el7_2.x86_64 samba-common-libs-4.2.12-7.el7_2.x86_64 xyz-libs-4.2.13-7.el7_2.x86_64

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-18 01:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found