Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: (jeffa) Re: Sorting Numbers

by Devo (Initiate)
on Nov 06, 2001 at 10:36 UTC ( [id://123524]=note: print w/replies, xml ) Need Help??


in reply to (jeffa) Re: Sorting Numbers
in thread Sorting Numbers

Yes, I do agree with your idea of simplicity...Open the file, dump in an array, then sort. I would like to solve it in two ways however, and avoid editing so much of the scripts. (This is a series of about 6 different scripts *reaching for aspirin*, all with user defined variables linked together in very odd ways....hence the problem I'm having here).

The data is tab deliminated and looks like this:

17 8/10/01 Joe Blow Joe@Blow.com New York webtherapist www.d +rudgereport.com I like green-eggs and ham,etc...

That's meant to be perceived as 8 different fields, the first being the number of the entry in which I wish to sort by...descending order of course.

Replies are listed 'Best First'.
Re: Re: (jeffa) Re: Sorting Numbers
by educated_foo (Vicar) on Nov 06, 2001 at 11:07 UTC
    From the perspective of sheer laziness, would it work to replace the
    "local ($a, $b) = @_"
    with a
    "local ($b, $a) = @_"
    ? Reversed sort order, no comprehension or re-writing required.

    /s

      Except of course $a and $b aren't actually passed into the sort function like that. Which is presumeably why that line is commented out :-)

      Blessed Be
      The Pixel

        Argh, how disgusting. But this should probably do the trick:
        local ($a, $b) = ($b, $a)
Re: Re: (jeffa) Re: Sorting Numbers
by mkmcconn (Chaplain) on Nov 07, 2001 at 20:04 UTC

    I understand the motive of trying to avoid editing the scripts, Devo, but in the long run if you stick with the previous author's plan, it's too fragile to maintain and impossible to safely extend.

    tilly wrote a nice discussion of Pass by reference vs globals, in a thread of nice discussions that's relevant to the maintenance problem you are facing (thus the need of aspirin)

    The true virtue of laziness is in saving everyone work. It is the most lazy thing, in this case, to edit out the costly, polluting mistakes in that code
    mkmcconn

Log In?
Username:
Password:

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

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

    No recent polls found