Perl file test operator help

Posted by Aaron Moodie on Stack Overflow See other posts from Stack Overflow or by Aaron Moodie
Published on 2010-04-18T04:03:40Z Indexed on 2010/04/18 4:13 UTC
Read the original article Hit count: 408

Filed under:
|

This is a really basic issue, but I'm new to perl and cannot work out what the issue is. I'm just trying to isolate the files in a directory, but the -d operator keeps treating all the folder contents as files ...

@contents is my array, and when I run this:

foreach $item(@contents) {
 if (-d $item) { next; }
 print"$item is a file\n"; 
}

I keep getting both folders and files. Alternatively, if I use -f, I get nothing.

edit: this is the output -

file01.txt is a file
folder 01  is a file
folder 02 is a file
Screen shot 2010-04-18 at 1.26.17 PM.png is a file

I'm running this on OSX

© Stack Overflow or respective owner

Related posts about perl

Related posts about beginner