<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>WEB-NES-BAY &#187; Sort Command</title>
	<atom:link href="http://webnesbay.com/tag/sort-command/feed/" rel="self" type="application/rss+xml" />
	<link>http://webnesbay.com</link>
	<description>Learn Tips and tricks on Linux, Hacking, linux, PHP, Perl, Web, Hardware</description>
	<lastBuildDate>Sun, 11 Apr 2010 05:12:40 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>How to make reverse sort in perl array</title>
		<link>http://webnesbay.com/how-to-make-reverse-sort-in-perl-array/</link>
		<comments>http://webnesbay.com/how-to-make-reverse-sort-in-perl-array/#comments</comments>
		<pubDate>Sat, 31 Oct 2009 03:42:47 +0000</pubDate>
		<dc:creator>WEBNESBAY</dc:creator>
				<category><![CDATA[Perl]]></category>
		<category><![CDATA[Alphabetical Order]]></category>
		<category><![CDATA[Array Array]]></category>
		<category><![CDATA[Arrays]]></category>
		<category><![CDATA[Canada Mexico]]></category>
		<category><![CDATA[Cmp]]></category>
		<category><![CDATA[Comparison Operator]]></category>
		<category><![CDATA[List Of Names]]></category>
		<category><![CDATA[Mexico Usa]]></category>
		<category><![CDATA[Perl Array]]></category>
		<category><![CDATA[Perl Project]]></category>
		<category><![CDATA[reverse sort]]></category>
		<category><![CDATA[reverse()]]></category>
		<category><![CDATA[Sort Command]]></category>
		<category><![CDATA[Sort Criteria]]></category>
		<category><![CDATA[Sort Function]]></category>
		<category><![CDATA[Variables]]></category>

		<guid isPermaLink="false">http://webnesbay.com/?p=901</guid>
		<description><![CDATA[I am working on some perl project. I have come across a situation where I need to sort the values in arrays in reverse order. I have done it very simply. I have an array of array: @array=qw(canada mexico usa);
Now I can use te sort() command to sort the above values in the array by giving the command: @sortthis=sort(@array); That uses alphabetical order for sorting by default. The sorting criteria is not given, but you can get same results by [...]


Related posts:<ol><li><a href='http://webnesbay.com/how-to-sort-ip-addresses-in-python/' rel='bookmark' title='Permanent Link: How to sort IP Addresses in python'>How to sort IP Addresses in python</a></li>
<li><a href='http://webnesbay.com/assigning-lists-and-arrays-in-perl/' rel='bookmark' title='Permanent Link: Assigning lists and arrays in PERL'>Assigning lists and arrays in PERL</a></li>
<li><a href='http://webnesbay.com/list-extract-and-compact-simple-but-very-useful-functions-in-php/' rel='bookmark' title='Permanent Link: List Extract and Compact simple but very useful functions in php'>List Extract and Compact simple but very useful functions in php</a></li>
</ol>]]></description>
			<content:encoded><![CDATA[<p>I am working on some perl project. I have come across a situation where I need to sort the values in arrays in reverse order. I have done it very simply. I have an array of array: @array=qw(canada mexico usa);</p>
<p>Now I can use te sort() command to sort the above values in the array by giving the command: @sortthis=sort(@array); That uses alphabetical order for sorting by default. The sorting criteria is not given, but you can get same results by giving a longer version of the sort function call, like so: @sortthis=sort {$a cmp $b} @array;</p>
<p>Here, $a and $b are special variables which are used to compare two of the values in @array to see which should come first in the sort order. The cmp is a comparison operator returns a positive value if $a &gt; $b, a negative value if $a &lt; $b, or zero if they are equal. By changing the formula that follows the sort keyword you can change the order of the sort function.</p>
<p>If you wanted to sort in reverse order, you could just use Perl&#8217;s reverse() function: @reversesort=reverse(@sortthis); or in one statement, @reversesort=reverse sort @array;. This is inefficient however as it must make a temporary copy of the list of names, which could get expensive if the array is large. A more efficient way is to just change the sort criteria to produce the reverse result. @reversesort=sort { $b cmp $a } @array;. Now, the values returned by cmp are the opposite of what they were above, and so the sort order is the opposite.</p>
<p><a href="http://www.bayview.com/blog/2008/08/08/sorting-in-reverse-order/"><strong>Source</strong></a></p>


<p>Related posts:<ol><li><a href='http://webnesbay.com/how-to-sort-ip-addresses-in-python/' rel='bookmark' title='Permanent Link: How to sort IP Addresses in python'>How to sort IP Addresses in python</a></li>
<li><a href='http://webnesbay.com/assigning-lists-and-arrays-in-perl/' rel='bookmark' title='Permanent Link: Assigning lists and arrays in PERL'>Assigning lists and arrays in PERL</a></li>
<li><a href='http://webnesbay.com/list-extract-and-compact-simple-but-very-useful-functions-in-php/' rel='bookmark' title='Permanent Link: List Extract and Compact simple but very useful functions in php'>List Extract and Compact simple but very useful functions in php</a></li>
</ol></p>]]></content:encoded>
			<wfw:commentRss>http://webnesbay.com/how-to-make-reverse-sort-in-perl-array/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
