And it's also worthwhile to know that every time you use any one of the -X operators on a given file, it fetches all the properties for the file (because that's how the underlying system library function works), and it keeps them in a cache, so if you use another -X function on the same file as the previous -X function, you can use "_" (underscore) instead of the file name or file handle, to use the cached info instead of reading it from disk again.
Plus, I like having things structured for loops, and I hate having to repeat things in my perl code when I shouldn't need to... even if it means using "eval" so that I can loop over the tests:
#!/usr/bin/perl use strict; use warnings; my %test = ( '-f' => 'a data file', '-d' => 'a directory', '-r' => 'readable', '-w' => 'writable', '-x' => 'executable', ); die "Usage: $0 [path/]file.name ...\n" unless @ARGV; for my $file ( @ARGV ) { my $report = "$file does not exist\n"; if ( -e $file ) { $report = "$file exists and is:\n"; for my $t ( sort keys %test ) { $report .= " ... $test{$t}\n" if ( eval "$t _" ); } } print "$report\n"; }
In reply to Re: A Tribute To The Monks Of Wisdom
by graff
in thread A Tribute To The Monks Of Wisdom
by koolgirl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |