Trevor Goddard wrote:
> >
> > -----Original Message-----
> > From: Rob Dixon [mailto:[EMAIL PROTECTED]
> > Sent: 16 April 2004 12:16
> > To: [EMAIL PROTECTED]; [EMAIL PROTECTED]
> > Subject: Re: How do I glob a limited number of files, sorted by creation
> > date
> > 
> > Trevor Goddard wrote:
> > >
> > > I want to be able to
> > >
> > > my $loc_src_dir = "g:\\inputdir\\";
> > > my @files = glob("$loc_src_dir*.txt");
> > >
> > > but only get the first 10 files sorted by creation date.
> > >
> > > I have had a look at the glob() and File::Glob() documentation but they
> > > don't seem to give me what I want.
> > 
> > This works fine for me Trevor. Are you /absolutely/ sure there aren't
> > just ten files in there? Try
> > 
> >   print map "$_\n", glob 'G:\inputdir\*.txt';
> > 
> > and see what you get. There's no reason I know of that 'glob'
> > should return only some of the files.
>
> I think you missed what I was trying to do. I know that there are more than
> 10 files, but I only want the first 10 that were created. The code I
> included gives you all of the files, I don't want that.

You're quite right: I imagined you had written ".. but I only get the first 10 files.."

I always discourage backticks or 'system' calls, but this seems to be a
good place for it to avoid writing several lines of Perl. Try this:

  my $loc_src_dir = "g:\\inputdir\\";
  my @files = (qx(dir $loc_src_dir*.txt /b /o-d))[0..9];
  chomp @files;

HTH,

Rob

_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to