Paul Harwood wrote:
>
> One question I have:
>
> With this statement:
>
> @files = sort { -M $a <=> -M $b } @files;
>
> How does Perl understand that these are files and not just text entries?
> Did using the readdir beforehand make this possible?

Well they /are/ just text entries! But ones that correspond to the names
of existing files. Strictly speaking it's possible for a file to have been
deleted between cataloguing it with 'readdir' and sorting the list,
but this will just give you a warning (if you have 'use warnings' set)
and sort the vanished file as if it had an age of zero days. If your
software is at all permanent then you can temporarily switch off that
particular warning by putting the statement in a block like this:

  {
    no warnings 'uninitialized';
    @files = sort { -M $a <=> -M $b } @files;
  }

(After that, you should really cope with the condition where /all/
of the files have been deleted in the interim so thet even the
oldest file doesn't exist :)

You also need to be aware that, unless the directory listing is
of your current directory each element needs to be prefixed with
the full path.

HTH,

Rob




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


Reply via email to