in reply to Re: Sort questions
in thread Sort questions

Works like a charm once the last compare was changed to
$a->[3] cmp $b->[3]
1. Is there a way to delineate the end of data block, something line __ENDOFDATA__ ( if it exists ) ?

2. I was thinking more in terms of packing or caching the sort keys, but now I really don't think that's necessary. The file only contains about 400 lines.

Thanks for your assistance.

Replies are listed 'Best First'.
Re^3: Sort questions
by Limbic~Region (Chancellor) on Jan 31, 2005 at 17:38 UTC
    wube,
    • Is there a way to delineate the end of data block, something line __ENDOFDATA__ ( if it exists )?
    • I don't believe so, but I am more interested in knowing why you would want to. I used __DATA__ because I assumed you were getting the data to populate the array from an external file. In this case, you would only need to open a filehandle for that file and replace the <DATA> with <FILEHANDLE>. If my assumption is wrong, please clarify and I will try and help you accomplish what you want.
    • I was thinking more in terms of packing or caching the sort keys, but now I really don't think that's necessary. The file only contains about 400 lines
    • That's why I recommended using a different data structure (such as an AoH) if you could. You would not have to use the Schwartzian Transform and your data would be more easily accessible. The other side to this is it would consume more memory.

    Cheers - L~R

      I used __DATA__ because I assumed you were getting the data to populate the array from an external file. In this case, you would only need to open a filehandle for that file and replace the <DATA> with <FILEHANDLE>.
      • You are absolutely correct. The final program will read input from an external file. But for testing purposes, I only wanted a subset. __DATA__ is a more elegant way of reading input data. Off course, being a newbie to Perl, I ended the data block with a blank line which set me off chasing shadows. Anyway, I finally realised what was causing the problem which led me to ask the __ENDofDATA__ question.
      The Schwartzian Transform is a very slick way of sorting. I like it. Sure glad you pointed it out.
      Thanks.
      wube