Keep It Simple, Stupid | |
PerlMonks |
Re: File handling basicsby vinoth.ree (Monsignor) |
on Jul 17, 2015 at 10:07 UTC ( [id://1135136]=note: print w/replies, xml ) | Need Help?? |
Include $! in die part of open(),It will give you the reason, why it can not open the file. Note that the file names in $file do not include the full path and do include "." and ".." which you probably don't care to have. You can eliminate them with,
The regular expression used in the grep can be extended to filter all sorts of ways, returning only files with a specific extension or starting with some text,etc. To check for all the subdirectories in a directory, try code like this:
It's a common mistake to leave out the $path from the -d check. If you do this, perl thinks you're talking about files in the current directory. Since the dirs don't -e in your current directory, they definitely don't -d. Exceptions are . and .., which exist in every directory. opendir, redir, closedir offer the most power and flexibility; but if you just want to read the files out of directory, you can also glob them:
All is well. I learn by answering your questions...
In Section
Seekers of Perl Wisdom
|
|