Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   help with Globbing : use of -r with glob catches only half of the matching files ... (http://www.velocityreviews.com/forums/t898454-help-with-globbing-use-of-r-with-glob-catches-only-half-of-the-matching-files.html)

xhoster@gmail.com 06-09-2006 08:25 PM

Re: help with Globbing : use of -r with glob catches only half of the matching files ...
 
"martin" <martps100@gmail.com> wrote:
> 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:

while (<FILEwithlistofFiles>) { #<----- loop here


> 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

--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB

martin 06-09-2006 09:10 PM

help with Globbing : use of -r with glob catches only half of the matching files ...
 
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.

I open a file that has a list of files with format of each line:

/dir1/subdir2/subdir3/file.xy <-- full path of a sample file

for any file "file.xy" there are several files in the system
such as

file.xy.0
file.xy.1
file.xy.1.2
file.xy.1.2.3
and one file which has the .ex at the end
file.ext.xy.1.2.4.ex


the part between .xy and .ex could be any number of times occurding
..[\d]*

My goal is to read list of files one by one and then to see if each
*.xy file has a corresponding *.xy....ex file.


I use this peace of code but out of 100 files, it only catches the
alternate files. and misses the other ones.

use strict;
use warnings;

my $globFile;

loop here ---> while (<FILEwithlistofFiles>) {
my $file = $_;

if (-r ($globFile = glob("$file*.ex"))) {
print " Found a matching file with .ex extension at the end.
print "found file is $globefile \n";
}
else {
print "missed to find the matching file with ending .ex extension in
the directory tree\n";
}

I should add that all the files are visible from the directory where I
invoke the script.

any help appreciated.

Thanks.



All times are GMT. The time now is 04:30 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.