> -----Original Message----- > From: Brian Volk [mailto:[EMAIL PROTECTED] > Sent: Monday, December 12, 2005 4:47 PM > To: beginners@perl.org > Subject: RE: sort files by creation time > > After running a few tests... :~) I think I might be able to sort on the > inode... ? Does this make sense? > > my @files = glob("/mnt/qdls/MSDSIN/*"); > > foreach my $file (@files) { > > print "$file\n"; > my $ino = (stat($file))[1]; > print "ino is $ino\n";
Looks like you're on the right track with the stat function, but you probably don't want to sort by the inode. A higher inode doesn't necessarily mean that a file was created later (think about deleted files). Keep reading up on stat... ry > > Thanks! > > Brian > > -----Original Message----- > From: Brian Volk [mailto:[EMAIL PROTECTED] > Sent: Monday, December 12, 2005 12:33 PM > To: 'beginners@perl.org' > Subject: sort files by creation time > > Hi All~ > > > > I'm using the glob function to grab all the files in a given directory and > then using crontab to check it every 5 minutes. Once I have the files I'm > using the diamond operator to read every line in every file and *do > something* if the line matches. Here's my questions: > > > > Given directory: > > File 1 - in dir at 9:01 > > File 2 - in dir at 9:02 > > File 3 - in dir at 9:03 > > > > I would like to process the File 1 first then File 2 and then File 3. > Each > file contains data that I need to print for that order. If I can process > the orders (File 1, File 2, File 3) according to the time they entered the > given dir (first in/first out) the data will print off in the correct > sequence. > > > > Is there a module I can use for this? Maybe File::Stat? Or can I do a > sort > of some kind right after the while <> ? > > > > Can someone pls let me know what function I'm supposed to use or which > module I need. > > > > Thanks!!! > > > > > > > > Below is some of the code: > > > > I'm using the code below to check if there are any files in the dir. If > so, > then goto to the PMSDS sub. > > > > my @files = glob("/home/bvolk/test_msds_in/*"); > > > > my $count = (); > > foreach my $file (@files) { > > $count++; > > if ($count > 0) { > > &PMSDS; > > last; > > > } > > } > > > > > > -----some of the PMSDS sub > > > > @ARGV = map { "$orders_dir/$_" } grep { !/^\./ } readdir ORDERS; > > > > my %DIR_LIST; > > > > $DIR_LIST{$_} = 1 for @pdfs; > > > > while (<>) { > > chomp; > > $_ =~ s/\s+\z//; > > > > if(exists($DIR_LIST{$_})){ > > my $basename = fileparse($ARGV,'.TXT'); > > $basename =~ s/O//; > > $_ =~ s/.pdf//i; > > > > print "Job $basename printing msds $_\n"; > > } else { > > my $basename = fileparse($ARGV,'.TXT'); > > $basename =~ s/O//; > > print "Job $basename missing msds $_\n" > > > > } > > } > > > > > > brian volk > > hpproducts.com > > [EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]> > > 317-298-9950 x1245 > > > > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > <http://learn.perl.org/> <http://learn.perl.org/first-response> > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>