Note that there are some explanatory texts on larger screens.

plurals
  1. POPerl Sort Array
    primarykey
    data
    text
    <p>I am trying to figure out how to sort list of file names in Perl.</p> <p>Each file is a PDF file that I am merging into a single pdf using Perl's PDF::Reuse</p> <p>Each pdf file name has two unique identifier. 1) is the account ID &amp; 2) report type.</p> <p>Example:</p> <p>C1234.lfs.pdf</p> <p>C1234 = account id lfs = report type.</p> <p>each account could have several reports that need to be in a specific order. </p> <p>How can I specify the order of report types? I want to use a config file where the script would look to see what order to sort each accounts reports before merging to 1 pdf file. Order I would like is:</p> <p>AcctId.lau.pdf AcctId.lsm.pdf AcctId.lad.pdf AcctId.lfs.pdf AcctId.lbe.pdf</p> <pre><code>@PDFS = (&lt;*l*.pdf&gt;); @REVERSED_LIST = reverse(@PDFS); prFile($OutPut); for my $pdf (@REVERSED_LIST) { next if($pdf eq $OutPut); &amp;Logit("Adding $pdf to $OutPut"); prDoc($pdf); } prEnd(); </code></pre> <p>Sorry if I am not explaining this correctly any help and suggestions are appreciated.</p> <p>New code being tested not giving correct order.</p> <pre><code>@PDFS = (&lt;*l*.pdf&gt;); my %lsfOrder = (lua=&gt;0, lsm=&gt;1, lfw=&gt;2); @SORTED = map { $_-&gt;[0] } # Take just the original file name sort { $a-&gt;[1] cmp $b-&gt;[1] ? $a-&gt;[1] cmp $b-&gt;[1] : # compare by account id if different $lsfOrder{$a-&gt;[2]} &lt;=&gt; $lsfOrder{$b-&gt;[2]} } map { [ $_, split('.', $_) ] # split into id/type once at the beginning } @PDFS; prFile($OutPut); for my $pdf (@SORTED) { next if($pdf eq $OutPut); &amp;Logit("Adding $pdf to $OutPut"); #print "Adding $pdf to $OutPut\n"; prDoc($pdf); } prEnd(); </code></pre>
    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.
    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