Harry Putnam wrote:
> Probably a no-brainer, but I wondered what is the canonical way or
> possibly a module that does this chore:
>
> Identify files by type similar to `-type' flag to unix `find' command.
> I first thought of the stat function, but I see I'm confused about
> what that does. None of the array elements are about type.
>
> One of them `mode' claims to be about `type' but I'm not conversant
> with the numeric output of that element. And it doesn't seem to be
> explained in language spoken by mortals in perldoc -f stat
> All the gobbledeegook about bit-anding masking etc would be rendered
> unecessary by an (often omitted) simple example.
> There is an example showing how to get the permissions from $mode but
> I couldn't begin to reverse engineer it to get type.
>
>
> Maybe File::Find has an option but I don't find it in the docs.
>
> Along with this `typing' action I wondered if there is a perl
> equivalent to unix `file' command.
>
> I browsed all the modules turned up with a search string of
>
> file type
> on cpan, but none revealed this functionality. At least not in a
> hasty scan.
It's a lot easier than that! Take a look at
perldoc -f -X
which (amongst a lot of other useful things) says:
-f File is a plain file.
-d File is a directory.
-l File is a symbolic link.
-p File is a named pipe (FIFO), or Filehandle is a pipe.
-S File is a socket.
-b File is a block special file.
-c File is a character special file.
-t Filehandle is opened to a tty.
So you can use:
if (-f $file) {
:
# process file
}
elsif (-d $file) {
:
# process directory
}
HTH,
Rob
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]