Re: sort files by creation time

2005-12-15 Thread Bob Showalter

Randal L. Schwartz wrote:

"Jeff" == Jeff Pang <[EMAIL PROTECTED]> writes:



Jeff> and we can use the _ handle to avoid stat'ing twice.
Jeff> Sorry,I don't know what is _ handle.Who help explain with it 
please,thanks.

It's documented.  I refuse to retype the docs for a thing. :)



Specifically, see

   perldoc -f stat

It's not always easy to figure out *where* something is documented :-)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: sort files by creation time

2005-12-14 Thread Randal L. Schwartz
> "Jeff" == Jeff Pang <[EMAIL PROTECTED]> writes:

Jeff> and we can use the _ handle to avoid stat'ing twice.
Jeff> Sorry,I don't know what is _ handle.Who help explain with it 
please,thanks.

It's documented.  I refuse to retype the docs for a thing. :)

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: sort files by creation time

2005-12-14 Thread Jeff Pang
and we can use the _ handle to avoid stat'ing twice.

Sorry,I don't know what is _ handle.Who help explain with it please,thanks.

-Original Message-
From: "Randal L. Schwartz" 
Sent: Dec 14, 2005 11:56 PM
To: beginners@perl.org
Subject: Re: sort files by creation time

>>>>> "Todd" == Todd W <[EMAIL PROTECTED]> writes:

Todd> my @files = map $_->[0],
Todd>  sort { $b->[1] <=> $a->[1] }
Todd>  map [ $_, -M ],
Todd>  grep -f, # get only plain files
Todd>  glob("/mnt/qdls/MSDSIN/*");

Since the map can also serve as a grep, and we can use the _ handle
to avoid stat'ing twice, this can be simplified to:

my @files =
  map $_->[0],
  sort { $b->[1] <=> $a->[1] }
  map { -f $_ ? [$_, -M _] : () }
  glob "...";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
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>




Re: sort files by creation time

2005-12-14 Thread Randal L. Schwartz
> "Todd" == Todd W <[EMAIL PROTECTED]> writes:

Todd> my @files = map $_->[0],
Todd>  sort { $b->[1] <=> $a->[1] }
Todd>  map [ $_, -M ],
Todd>  grep -f, # get only plain files
Todd>  glob("/mnt/qdls/MSDSIN/*");

Since the map can also serve as a grep, and we can use the _ handle
to avoid stat'ing twice, this can be simplified to:

my @files =
  map $_->[0],
  sort { $b->[1] <=> $a->[1] }
  map { -f $_ ? [$_, -M _] : () }
  glob "...";

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
 http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: sort files by creation time

2005-12-13 Thread JupiterHost.Net



OXx wrote:

Hello all,
I try to launch my perl application as a windows service.
I compile it with PAR so I have mysoft.exe
Then i installed  win32::daemon, no problem.
I try this script so:

use Win32::Daemon;


a) always always always:
use strict;
use warnings;
on code you post to this list


%Hash = (
machine =>  '',
name=>  'PerlTest',
display =>  'Oh my GOD, Perl is a service!',
path=>  'c:\\mysoft.exe',
user=>  '',

pwd =>  '',
description => 'First prog as service',
parameters =>'',
);
if( Win32::Daemon::CreateService( \%Hash ) )
{
print "Successfully added.\n";

}
else
{
print "Failed to add service: " . Win32::FormatMessage(
Win32::Daemon::GetLastError() ) . "\n";
}


b) what does this have to do with "sort files by creation time" ?

Start a new thread for new topics...

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: sort files by creation time

2005-12-13 Thread OXx
Hello all,
I try to launch my perl application as a windows service.
I compile it with PAR so I have mysoft.exe
Then i installed  win32::daemon, no problem.
I try this script so:

use Win32::Daemon;

%Hash = (
machine =>  '',
name=>  'PerlTest',
display =>  'Oh my GOD, Perl is a service!',
path=>  'c:\\mysoft.exe',
user=>  '',

pwd =>  '',
description => 'First prog as service',
parameters =>'',
);
if( Win32::Daemon::CreateService( \%Hash ) )
{
print "Successfully added.\n";

}
else
{
print "Failed to add service: " . Win32::FormatMessage(
Win32::Daemon::GetLastError() ) . "\n";
}

The service is installed ok but I have an error when I try to start the
service!
http://www.eventid.net/display.asp?eventid=7009&eventno=655&source=Service%20Control%20Manager&phase=1

Its a timeout error and I don'kow how to solve my problem...

If someone can help me
Thanks


RE: sort files by creation time

2005-12-13 Thread Brian Volk


-Original Message-
From: Brian Volk 
Sent: Tuesday, December 13, 2005 8:10 AM
To: 'Brian Franco'
Subject: RE: sort files by creation time



-Original Message-
From: Brian Franco [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 7:34 PM
To: Brian Volk
Subject: Re: sort files by creation time


 
 This will load @ARGV with the files in the current directory sorted 
 oldest -> newest:
 
   @ARGV = map $_->[0],
 sort { $b->[1] <=> $a->[1] }
 map [ $_, -M ],
 grep -f, # get only plain files
 <*>;
 
 How it works is left as an exercise for the reader :-)
 
 Thank you!  And I think I just bought the book that explains the above!
 Alpaca! Soon to find out! 
 
 Thanks again.
 
 Brian Volk


Brian,
whats the name of the book?

-Brian

The book is called Learning Perl Objects References and Modules.  It is the
follow up to Learning Perl.  Learning Perl is also known as the Llama and
the follow up is known as the Alpaca.  Randal L. Schwartz wrote both books
and the part I was referring to is actually named after him.  Schwartzian
transform.  You can read about it here:
http://en.wikipedia.org/wiki/Schwartzian_transform

Hope this helps.

Brian Volk

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Re: sort files by creation time

2005-12-13 Thread Bob Showalter

Brian Volk wrote:
Of course I 
have one more rookie question and a reference to a perldoc is just 
fine.  :~)  If I use the following code, why do I not need to declare 
the $a and the $b w/ my?


Correct. This is explained in perldoc perlvar:

   $a
   $b  Special package variables when using sort(), see "sort" in
   perlfunc.  Because of this specialness $a and $b don't need to
   be declared (using use vars, or our()) even when using the
   "strict 'vars'" pragma.  Don't lexicalize them with "my $a" or
   "my $b" if you want to be able to use them in the sort() com-
   parison block or function.


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: sort files by creation time

2005-12-12 Thread Brian Volk

Todd W wrote:


"Brian Volk" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
 


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";

Thanks!

   



Bob S gave you the answer. Change the line:

my @files = glob("/mnt/qdls/MSDSIN/*");

to:

my @files = map $_->[0],
sort { $b->[1] <=> $a->[1] }
map [ $_, -M ],
grep -f, # get only plain files
glob("/mnt/qdls/MSDSIN/*");

And you are all done.

Todd W.



 

Thank you to everyone for there responses...  Great stuff!  Of course I 
have one more rookie question and a reference to a perldoc is just 
fine.  :~)  If I use the following code, why do I not need to declare 
the $a and the $b w/ my?  I searched Google and found this " but rather 
are handed to the subroutine as the values of the global variables |$a| 
and |$b|."  does this mean $a and $b are built in variables which I do 
not need to declare?


Thanks again!
-
#!/usr/bin/perl

use strict;
use warnings;

my @files = glob("c:/brian/hp_work/text/*");

  foreach my $file ( sort {(stat($b))[9] <=> (stat($a))[9]} @files) 
{  
   
  print "$file\n";


   }
--
Brian Volk



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: sort files by creation time

2005-12-12 Thread Brian Volk


-Original Message-
From: Bob Showalter [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 4:44 PM
To: Brian Volk
Cc: 'beginners@perl.org'
Subject: Re: sort files by creation time

Brian Volk wrote:
> 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.  

This will load @ARGV with the files in the current directory sorted 
oldest -> newest:

   @ARGV = map $_->[0],
 sort { $b->[1] <=> $a->[1] }
 map [ $_, -M ],
 grep -f, # get only plain files
 <*>;

How it works is left as an exercise for the reader :-)

Thank you!  And I think I just bought the book that explains the above!
Alpaca! Soon to find out! 

Thanks again.

Brian Volk

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: sort files by creation time

2005-12-12 Thread Wagner, David --- Senior Programmer Analyst --- WGO
Brian Volk wrote:
> 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) {
Replace above line with:
foreach my $file ( sort {(stat($a))[9] <=> (stat($b))[9]} 
@files)
This wwill sort oldest file to newest. Change the a and b around for newest to 
oldest.

Wags ;)
> 
>  $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] 
> 
> 317-298-9950 x1245



***
This message contains information that is confidential
and proprietary to FedEx Freight or its affiliates.
It is intended only for the recipient named and for
the express purpose(s) described therein.
Any other use is prohibited.
***


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: sort files by creation time

2005-12-12 Thread Todd W

"Brian Volk" <[EMAIL PROTECTED]> wrote in message
news:[EMAIL PROTECTED]
> 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";
>
> Thanks!
>

Bob S gave you the answer. Change the line:

my @files = glob("/mnt/qdls/MSDSIN/*");

to:

my @files = map $_->[0],
 sort { $b->[1] <=> $a->[1] }
 map [ $_, -M ],
 grep -f, # get only plain files
 glob("/mnt/qdls/MSDSIN/*");

And you are all done.

Todd W.



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




RE: sort files by creation time

2005-12-12 Thread Ryan Frantz


> -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>




RE: sort files by creation time

2005-12-12 Thread Timothy Johnson

You could try something along these lines, where I create an array
prepending the date in Perl time format and then sort the array.  There
is probably a better way, but this would work.

Note:  (stat $file)[9] is a list slice that represents only the 9th
element of the list returned by 'stat $file'. Check out 'perldoc -f
stat'


###

use strict;
use warnings;

opendir(DIR,".") or die("Couldn't open '.'!");
my @files = readdir(DIR);

foreach my $file(@files){
#prepend the modified time
$file = (stat $file)[9].'#'.$file;
}

foreach my $sorted_file(sort @files){
#strip out the modified time so we're left with the file name
$sorted_file =~ s/^\d+\#//;
print "".localtime((stat $sorted_file)[9])." => $sorted_file\n";
}



-Original Message-
From: Brian Volk [mailto:[EMAIL PROTECTED] 
Sent: Monday, December 12, 2005 9:33 AM
To: 'beginners@perl.org'
Subject: sort files by creation time

Hi All~



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.  




--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




RE: sort files by creation time

2005-12-12 Thread Brian Volk
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";

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>




Re: sort files by creation time

2005-12-12 Thread Bob Showalter

Brian Volk wrote:

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.  


This will load @ARGV with the files in the current directory sorted 
oldest -> newest:


  @ARGV = map $_->[0],
sort { $b->[1] <=> $a->[1] }
map [ $_, -M ],
grep -f, # get only plain files
<*>;

How it works is left as an exercise for the reader :-)

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




sort files by creation time

2005-12-12 Thread Brian Volk
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]  

317-298-9950 x1245