[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] Ordering two lists



>Hi all!
>I'm banging my head against the wall... I have a list of filenames and
>the relative days-since-last-modification value...
>$dir ="Macintosh HD:Desktop Folder:Download";
>opendir (DIR, $dir)
>	or die "Non posso accedere a DIR: $!";
>
>while (defined(my $nomeFile = readdir (DIR))) {
>	$nomeFile = $dir.":".$nomeFile;
>	$gg = int (-M $nomeFile);
>}

    Here's a simple way:  (I'm not very good at elegant Perl)

-Andrew

------------

$dir ="Macintosh HD:Desktop Folder:Download";

@items = ();

opendir (DIR, $dir) or die "Non posso accedere a DIR: $!";
while (defined(my $nomeFile = readdir (DIR))) {
	$nomeFile = $dir.":".$nomeFile;
	$gg = int (-M $nomeFile);

	$aRef = [$gg, $nomeFile];
	push @items, $aRef;
}
closedir (DIR);

@newlist = sort {$a->[0] <=> $b->[0];} @items;
foreach $item (@newlist)
{
	print "$$item[1] with mod date of $$item[0]\n";
}

-------------

/*-------------------------------------------------------------
Andrew O. Mellinger                      Direct: (503) 265-1220
Critical Path Software, Inc.               Main: (503) 222-2922
General Specialist                          Fax: (503) 222-3020
mailto:andrew@criticalpath.com      http://www.criticalpath.com
-------------------------------------------------------------*/

# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org