<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2//EN">
<HTML>
<HEAD>
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=us-ascii">
<META NAME="Generator" CONTENT="MS Exchange Server version 5.5.2657.73">
<TITLE>RE: [Kc] sort by mod date [x-adr][x-sls]</TITLE>
</HEAD>
<BODY>

<P><FONT SIZE=2>jyoung79 at kc dot rr dot com wrote:</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; I'm new to Perl and I was just curious if anyone here had</FONT>
<BR><FONT SIZE=2>&gt; any thoughts about the code below.&nbsp; I'm running this on OS</FONT>
<BR><FONT SIZE=2>&gt; X (currently using an app called 'Affrus') and it sorts</FONT>
<BR><FONT SIZE=2>&gt; the files by modification date.&nbsp; Here's my original code:</FONT>
<BR><FONT SIZE=2>...</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; I asked this question also on the OS X Perl List and Jarkko</FONT>
<BR><FONT SIZE=2>&gt; had sent this:</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; -------</FONT>
<BR><FONT SIZE=2>&gt; opendir(DIR, shift || &quot;.&quot;) &amp;&amp; print map { &quot;$_-&gt;[1]\n&quot; }</FONT>
<BR><FONT SIZE=2>&gt; sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] || $a-&gt;[1] cmp $b-&gt;[1] }</FONT>
<BR><FONT SIZE=2>&gt; map { [ (stat($_))[9], $_ ] } grep { !/^\.{1,2}$/ }</FONT>
<BR><FONT SIZE=2>&gt; readdir(DIR)</FONT>
<BR><FONT SIZE=2>&gt; -------</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; which I thought looked really cool, so I changed it a bit to:</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; -------</FONT>
<BR><FONT SIZE=2>&gt; opendir(DIR, shift || &quot;/Users/jay/Desktop/Other Stuff/old stuff 4&quot;)</FONT>
<BR><FONT SIZE=2>&gt; &amp;&amp; print map { &quot;$_-&gt;[1]\n&quot; } sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] </FONT>
<BR><FONT SIZE=2>&gt; || $a-&gt;[1] cmp $b-&gt;[1] } map { [ (stat($_))[9], $_ ] }</FONT>
<BR><FONT SIZE=2>&gt; grep { !/^\.{1,2}$/ } readdir(DIR)</FONT>
<BR><FONT SIZE=2>&gt; -------</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; but I never could make it work.&nbsp; It kept giving me these errors:</FONT>
<BR><FONT SIZE=2>&gt; </FONT>
<BR><FONT SIZE=2>&gt; *&nbsp; Argument (file name) isn't numeric in numeric comparison (&lt;=&gt;)</FONT>
<BR><FONT SIZE=2>&gt; *&nbsp; (62) Use of uninitialized value in string comparison (cmp)</FONT>
</P>
<BR>

<P><FONT SIZE=2>The script works for me on a Win32 system. Did you cut and past from your script or re-type it? </FONT>
</P>
<BR>

<P><FONT SIZE=2>The part which looked odd to me on my initial reading was:</FONT>
</P>

<P><FONT SIZE=2>&gt; sort { $a-&gt;[0] &lt;=&gt; $b-&gt;[0] || $a-&gt;[1] cmp $b-&gt;[1] }</FONT>
</P>

<P><FONT SIZE=2>I haven't seen that before. But I guess I can see how it's useful in this case. It basically means sort numerically by file modification time, sorting further by filename where the modification times are equal.</FONT></P>
<BR>

<P><FONT SIZE=2>You might see what the following produces:</FONT>
</P>

<P><FONT SIZE=2>opendir(DIR, shift || &quot;/Users/jay/Desktop/Other Stuff/old stuff 4&quot;);</FONT>
<BR><FONT SIZE=2>for my $i (grep { !/^\.{1,2}$/ } readdir(DIR)) {</FONT>
<BR><FONT SIZE=2>&nbsp; print '['. (stat($i))[9] . &quot;, $i]\n&quot;</FONT>
<BR><FONT SIZE=2>}</FONT>
</P>

<P><FONT SIZE=2>That'll print out the contents of the list of anonymous array references which are being sorted. For me it looked something like:</FONT></P>

<P><FONT SIZE=2>[1087217796, 1]</FONT>
<BR><FONT SIZE=2>[1087217802, 2]</FONT>
<BR><FONT SIZE=2>[1087217798, 3]</FONT>
<BR><FONT SIZE=2>[1087217794, a]</FONT>
<BR><FONT SIZE=2>[1087217800, b]</FONT>
<BR><FONT SIZE=2>[1087217790, c]</FONT>
<BR><FONT SIZE=2>[1087219921, kcpm.pl]</FONT>
</P>

<P><FONT SIZE=2>I don't imagine it'll look the same for you... or else you wouldn't be getting that &quot;isn't numeric&quot; error when making a comparison like {$a-&gt;[0] &lt;=&gt; $b-&gt;[0]} where for the first two elements in my example, the block should reduce to {1087217796 &lt;=&gt; 1087217802}.</FONT></P>

<P><FONT SIZE=2>--</FONT>
<BR><FONT SIZE=2>Garrett Goebel</FONT>
<BR><FONT SIZE=2>IS Development Specialist</FONT>
</P>

<P><FONT SIZE=2>ScriptPro&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Direct: 913.403.5261</FONT>
<BR><FONT SIZE=2>5828 Reeds Road&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Main: 913.384.1008</FONT>
<BR><FONT SIZE=2>Mission, KS 66202&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Fax: 913.384.2180</FONT>
<BR><FONT SIZE=2>www.scriptpro.com&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; garrett@scriptpro.com</FONT>
</P>

</BODY>
</HTML>