Loading ...
Sorry, an error occurred while loading the content.

RE: [PBML] PERL sort help please?

Expand Messages
  • Sheldon Smith
    The basic Perl sort looks at the list as simple strings. You need to define a subroutine that: compares two strings $a and $b and returns -1 if $a should be
    Message 1 of 4 , Oct 30, 2000
    • 0 Attachment
      The basic Perl sort looks at the list as simple strings.

      You need to define a subroutine that:
      compares two strings $a and $b and
      returns -1 if $a should be before $b,
      0 if $a and $b are equal, and
      1 if $a should be after $b.
      Look at the PERLFUNC man page.

      Call the subroutine "by_position", and invoke as

      ... sort by_position (@list) ...

      Depending on the amount of data, it may or may not be faster. I would expect
      a moderately sized file to sort quicker with an executable sort program
      rather than Perl's "bytecode".
      If the file(s) are small enough, it will be faster to sort within Perl
      instead of forking a process off.
      If the file(s) are big enough, Perl will run out of virtual memory.

      > -----Original Message-----
      > From: Eric Via [mailto:ericvia@...]
      > Sent: Monday, October 30, 2000 4:20 PM
      > Subject: [PBML] PERL sort help please?
      >
      > Greetings folks!
      >
      > I'm having a heck of a time understanding the way in which
      > Perl can sort -
      > the whole reason I'm trying to convert a standard UNIX sort
      > into a Perl sort
      > is I want to see which one's faster - so if you can tell me
      > right now that a
      > Perl sort won't move as quickly as a standard UNIX I'll be happy.
      >
      > My sort looks like:
      >
      > sort -o mysort.srt -T /data/$PRJ_ENVIRONMENT/evia/work -k 1.3,1.18
      > -k 1.1,1.1 -k 1.59r,1.66 -k 1.2,1.2 sortthis.txt sortthat.txt
      >
      > (Which is basically sorting 2 files:
      >
      > Sort by position 1.3 to 1.18,
      > Sort by position 1.1 to 1.1
      > Reverse sort by positoin 1.2 to 1.2
    • Eric Via
      The date was 10/30/00, and the clock on the mantle read 5:16 PM -0600 ... Hmm - and this is a big big file - of probably close to half a million records - from
      Message 2 of 4 , Oct 30, 2000
      • 0 Attachment
        The date was 10/30/00, and the clock on the mantle read 5:16 PM -0600
        when Sheldon Smith sat down at the computer and began to type:

        >The basic Perl sort looks at the list as simple strings.
        >
        >You need to define a subroutine that:
        >compares two strings $a and $b and
        >returns -1 if $a should be before $b,
        > 0 if $a and $b are equal, and
        > 1 if $a should be after $b.

        Hmm - and this is a big big file - of probably close to half a
        million records - from the sound of things sounds like I may be
        better off avoiding the Perl sort.

        >Look at the PERLFUNC man page.

        Funny thing there Sheldon - I have already tried this - but it's
        not found on my machine.

        >Call the subroutine "by_position", and invoke as
        >
        > ... sort by_position (@list) ...
        >
        >Depending on the amount of data, it may or may not be faster. I would expect
        >a moderately sized file to sort quicker with an executable sort program
        >rather than Perl's "bytecode".

        I think you're right my friend.

        >If the file(s) are small enough, it will be faster to sort within Perl
        instead of forking a process off.
        >If the file(s) are big enough, Perl will run out of virtual memory.

        It's a big one alright.

        Thanks VERY much for the prompt and wonderful answer Sheldon - I
        hope one day I am able to assist you so well.

        Have a Happy Halloween!

        Eric
        --
        ------------------------------------
        Eric Via
        ericvia@...
        My home page: http://web2.airmail.net/ericvia/ericpage.html
        (Buddhism, VW New Beetle, Mercedes, Spam, Jokes, D.B. Cooper,
        Trains, & more!)
        OM MANI PADME HUM
        ------------------------------------
        A flower falls, even though we love it; and a weed grows, even though
        we do not love it.
        -Dogen
      • francisco reyes
        ... With so many records it may be worth your time to work with a database. Then you could do all kinds of sorts/queries with your data. You could try Mysql or
        Message 3 of 4 , Nov 1, 2000
        • 0 Attachment
          --- In perl-beginner@egroups.com, Eric Via <ericvia@a...> wrote:
          > Hmm - and this is a big big file - of probably close to half a
          > million records - from the sound of things sounds like I may be
          > better off avoiding the Perl sort.

          With so many records it may be worth your time to work with a
          database. Then you could do all kinds of sorts/queries with your data.

          You could try Mysql or PostgreSQL
        • Eric Via
          The date was 11/1/00, and the clock on the mantle read 5:18 PM +0000 ... I have and will continue to look at those for sure my friend - thanks very much for
          Message 4 of 4 , Nov 1, 2000
          • 0 Attachment
            The date was 11/1/00, and the clock on the mantle read 5:18 PM +0000
            when francisco reyes sat down at the computer and began to type:

            >
            >With so many records it may be worth your time to work with a
            >database. Then you could do all kinds of sorts/queries with your data.
            >
            >You could try Mysql or PostgreSQL

            I have and will continue to look at those for sure my friend -
            thanks very much for the advice!

            EV

            --
            ------------------------------------
            Eric Via
            ericvia@...
            My home page: http://web2.airmail.net/ericvia/ericpage.html
            (Buddhism, VW New Beetle, Mercedes, Spam, Jokes, D.B. Cooper,
            Trains, & more!)
            OM MANI PADME HUM
            ------------------------------------
            A flower falls, even though we love it; and a weed grows, even though
            we do not love it.
            -Dogen
          Your message has been successfully submitted and would be delivered to recipients shortly.