[Kc] sort by mod date (Mac OS X specific)

Garrett Goebel garrett at scriptpro.com
Wed Jun 16 09:09:09 CDT 2004


JYOUNG79 at kc dot rr dot com wrote:
> 
> Sorry for my delayed response.
> 
> > > but I never could make it work.  It kept giving me these errors:
> > > 
> > > *  Argument (file name) isn't numeric in numeric comparison (<=>)
> > > *  (62) Use of uninitialized value in string comparison (cmp)
> > 
> > 
> > The script works for me on a Win32 system. Did you cut and past from 
> > your script or re-type it?
> 
> I had pasted it.
> 
> 
> > You might see what the following produces:
> > 
> > opendir(DIR, shift || "/Users/jay/Desktop/Other Stuff/old stuff 4"); 
> > for my $i (grep { !/^\.{1,2}$/ } readdir(DIR)) {  print '['. 
> > (stat($i))[9] . ", $i]\n"
> > }
> 
> Hmm.  I can't seem to make this work.  It's giving me this error:
> 
> (19) Use of uninitialized value in concatenation (.) or string
> 
> The debugger is giving me this:
> 
> [1086789289, .DS_Store]
> [, 3002 copy 2]
> [, BullsEye Builder]
> [, BullsEye Builder copy]
> [, BullsEye Builder-Prefs.txt]
> [, BullsEye Builder-Prefs.txt old just in case] [, Convert Quark
> 4 to 6.applescript] [, droplet and applett  test] [, dude] [, 
> dude2] [, GA_Template.qxd 1] [, illust1.scpt] [, illust2.scpt] 
> [, illust3.scpt] [, Indigo Proofer X] [, Indigo Proofer X = 
> backup] [, Personal Macro Workbook] [, property test] [, untitled 
> folder] [, 'Ä¢ IndigoPPDs] Use of uninitialized value in 
> concatenation (.) or string at /Volumes/Data 1/Perl Stuff/Garrett's
> sort example.pl line 3.
> ...
> (That last line is repeated 19 times (basically for each item))
> 
> The debugger points to line 3 as the error:
> 
> print '['. (stat($i))[9] . ", $i]\n" 
> 
> It looks like it doesn't want to work with 'stat' for some reason.
> It might also be this program I'm using (as well as it being on a 
> Mac).  I'm sure I'm just missing something simple here with my lack
> of knowledge, but let me know if you see something I'm missing.

Given the original error, that's pretty much where I expected the problem to
be. Odd that the first call to stat worked. Perhaps it is the odd characters
in the subsequent filenames.  Quoting filenames on various OS's sometimes
works around this. -Though I wouldn't think it'd be necessary for stat...
Perhaps give this a try:

opendir(DIR, shift || "/Users/jay/Desktop/Other Stuff/old stuff 4"); 
for my $i (grep { !/^\.{1,2}$/ } readdir(DIR)) {
  print '['. (stat('"'.$i.'"'))[9] . ", $i]\n";
}

If that gives more promising results, the modified original script would
look like:

opendir(DIR, shift || "/Users/jay/Desktop/Other Stuff/old stuff 4") or die
$!;
print map { "$_->[1]\n" } 
      sort { $a->[0] <=> $b->[0] || $a->[1] cmp $b->[1] }
      map { [ (stat('"'.$_.'"'))[9], $_ ] }
      grep { !/^\.{1,2}$/ }
      readdir(DIR)


If that doesn't work, we might try looking at adding a:

use File::Spec::Functions qw(:ALL);

and replacing stat($_) with stat(canonpath(rel2abs($_)))



I hope one of our Mac Perl folks will take a look at this...

--
Garrett Goebel
IS Development Specialist

ScriptPro                   Direct: 913.403.5261
5828 Reeds Road               Main: 913.384.1008
Mission, KS 66202              Fax: 913.384.2180
www.scriptpro.com          garrett at scriptpro.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.pm.org/pipermail/kc/attachments/20040616/981b71c2/attachment.htm


More information about the kc mailing list