Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I have to disagree with everyone. Standard "lists are too large" approaches such as Sort::External are coded to handle the case of too many lines, not lines that are too large. I would expect this to be true of the Unix sort utility as well, though it makes sense to try it to verify that.

Assuming that that doesn't work, what you need to do is use read to scan the file to find all of the starts of lines (they are 1 after the returns). Then you sort this array of offsets with a comparison function that does a string comparison between what is in the file at the two different locations. You of course don't want to pull in the full line to do that, instead use seek and read to move to the the right spots, and pulls a block each, then compares them, repeating as need be. Then you take this sorted array and use it to write out a sorted file by taking each offset, extracting the string in pieces and writing it to the output.

This is kind of complex and I'd code you an explanatory example if I was not currently typing one-handed due to a hand injury. :-(

Update: As BrowserUk notes, your question is unclear. I read it as lines up to 2 GB. If that is wrong, then this answer is inappropriate.


In reply to Re: Sorting Gigabytes of Strings Without Storing Them by tilly
in thread Sorting Gigabytes of Strings Without Storing Them by neversaint

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-04-25 08:23 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found