Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: sorting numbers

by stephen (Priest)
on Apr 10, 2002 at 23:04 UTC ( #158157=note: print w/ replies, xml ) Need Help??


in reply to sorting numbers

A few things to get you going.

First, to pull the 't=' numbers out of the file, you need to use backreferences. That's when you put something in parens in a regular expression, like so:

m/A t=(d*)/; my $t_val = $1;
If $_ were
hello A t=40a30
then $t_val would be 40.

Next, you need to use sort. sort operates on a list, like so:

my @list = ('my', 'bonnie', 'lies'); foreach my $word (sort @list) { print $word, "\n"; }
The result is:
bonnie lies my

sort normally sorts alphabetically. To sort numerically, see the perlfunc:sort manual page.

To collect all of these numbers into a list, you'll need push. Now all you need to do is put these pieces together. :)

stephen


Comment on Re: sorting numbers
Select or Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (11)
As of 2015-07-30 07:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (270 votes), past polls