Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: divide by '/'

by idnopheq (Chaplain)
on Apr 10, 2001 at 23:36 UTC ( [id://71548]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to divide by '/'

I went with a split, hash, and sort method.

#!/usr/bin/perl -w # slurped file in @numbers # final outcome in %numHash @numbers = ( "432/205", "905/4578", "623/4568", "1/10009", "10/10005" +); foreach ( @numbers ) { ($key, $value) = split /\//, $_; $numHash{$key} = $value; } # UPDATED foreach $numerator ( sort { $a <=> $b } keys %numHash ) { print $numerator , '/' , $numHash{$numerator} , "\n"; }

TIMTOWTDI
Dex

p.s. - mine won't handle leading zeros, but the pizza man is en route!

UPDATE 0: - forgot my <=>!!!!! Need fud!

UPDATE 1: - check out how do i sort hash by key numerically

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://71548]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.