Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > help with Globbing : use of -r with glob catches only half of the matching files ...

Reply
Thread Tools

help with Globbing : use of -r with glob catches only half of the matching files ...

 
 
xhoster@gmail.com
Guest
Posts: n/a
 
      06-09-2006
"martin" <> 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
 
Reply With Quote
 
 
 
 
martin
Guest
Posts: n/a
 
      06-09-2006
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.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
ie7 displaying only half of page (cuts page in half)... trint ASP .Net 4 09-11-2007 10:56 AM
glob.glob unicode bug or feature Elbert Lev Python 5 08-02-2004 12:09 AM
Question about glob.glob <--newbie Sean Berry Python 3 05-04-2004 05:34 PM
RE: Bug in glob.glob for files w/o extentions in Windows Tim Peters Python 1 12-01-2003 09:22 AM
Bug in glob.glob for files w/o extentions in Windows Georgy Pruss Python 15 12-01-2003 04:04 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57