X
xhoster
martin said:Hi, I am trying to use a combination of file test with '-r' and file
globbing to check existense of a certain number of files on a linux
system. I appreciate any help on this, as I catch only half of the
files that are supposed to be detected.
from perldoc perlop:
A (file)glob evaluates its (embedded) argument only when it is
starting a new list. All values must be read before it will start
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
over. In list context, this isn't important because you
^^^^
automatically get them all anyway. However, in scalar context the
operator returns the next value each time it's called, or "undef"
when the list has run out. As with filehandle reads, an automatic
"defined" is generated when the glob occurs in the test part of a
"while", because legal glob returns (e.g. a file called 0) would
otherwise terminate the loop. Again, "undef" is returned only once.
So if you're expecting a single value from a glob, it is much better
to say
($file) = <blurch*>;
than
$file = <blurch*>;
loop here ---> while (<FILEwithlistofFiles>) {
Perl already has a system for comments. Please use it
rather than making up your own:
my $file = $_;
if (-r ($globFile = glob("$file*.ex"))) {
my ($globFile)= glob("$file*.ex"); # call in list context
if (defined $globFile and -r $globFile) {
Cheers,
Xho