Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to sort rows in a text file in Perl?
    primarykey
    data
    text
    <p>I have a couple of text files (<code>A.txt</code> and <code>B.txt</code>) which look like this (might have ~10000 rows each)</p> <pre><code>processa,id1=123,id2=5321 processa,id1=432,id2=3721 processa,id1=3,id2=521 processb,id1=9822,id2=521 processa,id1=213,id2=1 processc,id1=822,id2=521 </code></pre> <p>I need to check if every row in file <code>A.txt</code> is present in <code>B.txt</code> as well (<code>B.txt</code> might have more too, that is okay).</p> <p>The thing is that rows can be in any order in the two files, so I am thinking I will sort them in some particular order in both the files in <code>O(nlogn)</code> and then match each line in <code>A.txt</code> to the next lines in <code>B.txt</code> in <code>O(n)</code>. I could implement a hash, but the files are big and this comparison happens only once after which these files are regenerated, so I don't think that is a good idea.</p> <p><strong>What is the best way to sort the files in Perl?</strong> Any ordering would do, it just needs to be <em>some</em> ordering.</p> <p>For example, in dictionary ordering, this would be</p> <pre><code>processa,id1=123,id2=5321 processa,id1=213,id2=1 processa,id1=3,id2=521 processa,id1=432,id2=3721 processb,id1=9822,id2=521 processc,id1=822,id2=521 </code></pre> <p>As I mentioned before, any ordering would be just as fine, as long as Perl is fast in doing it.</p> <p>I want to do it from within Perl code, after opening the file like so</p> <pre><code>open (FH, "&lt;A.txt"); </code></pre> <p>Any comments, ideas etc would be helpful.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload