<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Why doesn't sort work? in Operating System - HP-UX</title>
    <link>https://community.hpe.com/t5/operating-system-hp-ux/why-doesn-t-sort-work/m-p/2709466#M723552</link>
    <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I'm trying my hand at perl and I have a problem. I have an array with the values&lt;BR /&gt;100.9, 10.3, 12, 50, -38&lt;BR /&gt;I do this:&lt;BR /&gt;@array2 = sort @array1;&lt;BR /&gt;&lt;BR /&gt;Instead of coming out in correct order, array2 prints out like this:&lt;BR /&gt;-38, 10.3, 100.9, 12, 50&lt;BR /&gt;&lt;BR /&gt;What is wrong with perl's sort?&lt;BR /&gt;&lt;BR /&gt;Thanks, John W.&lt;BR /&gt;</description>
    <pubDate>Tue, 23 Apr 2002 17:31:52 GMT</pubDate>
    <dc:creator>John Wolfe_1</dc:creator>
    <dc:date>2002-04-23T17:31:52Z</dc:date>
    <item>
      <title>Why doesn't sort work?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/why-doesn-t-sort-work/m-p/2709466#M723552</link>
      <description>Hello,&lt;BR /&gt;&lt;BR /&gt;I'm trying my hand at perl and I have a problem. I have an array with the values&lt;BR /&gt;100.9, 10.3, 12, 50, -38&lt;BR /&gt;I do this:&lt;BR /&gt;@array2 = sort @array1;&lt;BR /&gt;&lt;BR /&gt;Instead of coming out in correct order, array2 prints out like this:&lt;BR /&gt;-38, 10.3, 100.9, 12, 50&lt;BR /&gt;&lt;BR /&gt;What is wrong with perl's sort?&lt;BR /&gt;&lt;BR /&gt;Thanks, John W.&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Apr 2002 17:31:52 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/why-doesn-t-sort-work/m-p/2709466#M723552</guid>
      <dc:creator>John Wolfe_1</dc:creator>
      <dc:date>2002-04-23T17:31:52Z</dc:date>
    </item>
    <item>
      <title>Re: Why doesn't sort work?</title>
      <link>https://community.hpe.com/t5/operating-system-hp-ux/why-doesn-t-sort-work/m-p/2709467#M723553</link>
      <description>Hi John:&lt;BR /&gt;&lt;BR /&gt;The simple answer is that sort is doing just what you are telling it to do. In the absense of a comparison routine, sort sorts in lexical order but you obviously want numeric order. The cure is quite simple: supply a comparison subroutine. In this case, we can use the inline method via the 'spaceship' operator.&lt;BR /&gt;&lt;BR /&gt;@array2 = sort {$a &amp;lt;=&amp;gt; $b} @array1;&lt;BR /&gt;&lt;BR /&gt;In the case, &amp;lt; 0 is returned if a &amp;lt; b; 0 if a = b; and &amp;gt; 0 is a &amp;gt; b. You can reverse the order of the sort by using {$b &amp;lt;=&amp;gt; $a}.&lt;BR /&gt;&lt;BR /&gt;This should fix you, Clay&lt;BR /&gt;</description>
      <pubDate>Tue, 23 Apr 2002 17:36:49 GMT</pubDate>
      <guid>https://community.hpe.com/t5/operating-system-hp-ux/why-doesn-t-sort-work/m-p/2709467#M723553</guid>
      <dc:creator>A. Clay Stephenson</dc:creator>
      <dc:date>2002-04-23T17:36:49Z</dc:date>
    </item>
  </channel>
</rss>

