Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

Re: sort on numbers embedded in text

by Shendal (Hermit)
on Oct 09, 2000 at 19:21 UTC ( [id://35918]=note: print w/replies, xml ) Need Help??


in reply to sort on numbers embedded in text

Although from your question it is a bit unclear what you are looking for, perhaps the following code segment will help.
#/usr/bin/perl -w use strict; foreach (sort split /\s+/,<DATA>) { /^\d/ ? print "FH1: $_\n" : print "FH2: $_\n"; } __DATA__ 953-FMT-FMT 954-FMT-FMT BLOGO93-FMT-FMT 955-FMT-FMT BOXSTART2- +FMT-FMT BOXEND2-FMT-FMT 956-FMT-FMT 413-FMT-FMT DATE1-FMT-FMT + 414-FMT-FMT 415-FMT-FMT 416-FMT-FMT BLOGO107-FMT-FMT 417-F +MT-FMT 419-FMT-FMT 418-FMT-FMT BLOGO63-FMT-FMT 393-FMT-FMT +394-FMT-FMT BLOGO75-FMT-FMT 420-FMT-FMT 421-FMT-FMT 395-FMT-F +MT
Which outputs...
FH1: 393-FMT-FMT FH1: 394-FMT-FMT FH1: 395-FMT-FMT FH1: 413-FMT-FMT FH1: 414-FMT-FMT FH1: 415-FMT-FMT FH1: 416-FMT-FMT FH1: 417-FMT-FMT FH1: 418-FMT-FMT FH1: 419-FMT-FMT FH1: 420-FMT-FMT FH1: 421-FMT-FMT FH1: 953-FMT-FMT FH1: 954-FMT-FMT FH1: 955-FMT-FMT FH1: 956-FMT-FMT FH2: BLOGO107-FMT-FMT FH2: BLOGO63-FMT-FMT FH2: BLOGO75-FMT-FMT FH2: BLOGO93-FMT-FMT FH2: BOXEND2-FMT-FMT FH2: BOXSTART2-FMT-FMT FH2: DATE1-FMT-FMT

Cheers,
Shendal

Log In?
Username:
Password:

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

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

    No recent polls found