Beefy Boxes and Bandwidth Generously Provided by pair Networks
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: Sorting within a file

by dmorelli (Scribe)
on Mar 04, 2005 at 20:53 UTC ( [id://436749]=note: print w/replies, xml ) Need Help??


in reply to Sorting within a file

#! /usr/bin/perl -w use strict; # Read whole file into a list, this could be an open()ed filehandle # instead of the DATA section from below my @lines = <DATA>; # Sort the list by comparing the numeric portion of the lines my @sorted = sort { my ($numA) = $a =~ /^(\d+).*/; my ($numB) = $b =~ /^(\d+).*/; $numA <=> $numB } @lines; # Output the sorted list { # We never chomped, the lines still contain newlines, # so don't need a list separator local $" = ""; print "@sorted"; } __DATA__ 1260896 abadeno 972 achin00 402 astamen 181847 azeleke 134 b005376 1 b005824

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (6)
As of 2024-04-23 13:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found