Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The reason why you're encountering difficulties is the operator, <code>&lt;=&gt;</code> is the numeric comparison, <code>cmp</code> is the <em>default</em> and it is string comparison.</p> <pre><code>$ perl -E'say for sort qw/01 1 02 200/'; 01 02 1 200 </code></pre> <p>With a slight modification we get something much closer to correct:</p> <pre><code>$ perl -E'say for sort { $a &lt;=&gt; $b } qw/01 1 02 200/'; 01 1 02 200 </code></pre> <p>However, in your case you need to remove the non digits.</p> <pre><code>$ perl -E'say for sort { my $s1 = $a =~ m/(\d+)/; my $s2 = $b =~ /(\d+)/; $s1 &lt;=&gt; $s2 } qw/01 1 02 200/'; 01 1 02 200 </code></pre> <p>Here is it more pretty:</p> <pre><code>sort { my $s1 = $a =~ m/(\d+)/; my $s2 = $b =~ /(\d+)/; $s1 &lt;=&gt; $s2 } </code></pre> <p>This isn't flawless, but it should give you a good idea of your issue with sort.</p> <p>Oh, and as a follow up, the <strong>Shcwartzian Transform</strong> solves a different problem: it stops you from having to run a complex task (unlike the one you're needing -- a regex) multiple times in the search algorithm. It comes at a memory cost of having to cache the results (not to be unexpected). Essentially, what you do is map the input of the problem, to the output (typically in an array) <code>[$input, $output]</code> then you sort on the outputs <code>$a-&gt;[1] &lt;=&gt; $b-&gt;[1]</code>. With your stuff now sorted you map back over to get your original inputs <code>$_-&gt;[0]</code>.</p> <pre><code>map $_-&gt;[0], sort { $a-&gt;[1] &lt;=&gt; $b-&gt;[1] } map [ $_, fn($_) ] , qw/input list here/ ; </code></pre> <p>It is cool because it is so compact while being so efficient.</p>
    singulars
    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.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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