[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
QuickScan mystery resolved
From: |
Zachary Deretsky |
Subject: |
QuickScan mystery resolved |
Date: |
Fri, 3 Nov 2000 17:16:38 -0800 |
do {} while (<cond>); is no different than, for
example:
print if (/pattern/);
Been around for a long long time.
-Peter
---
Peter A. Vogel
[Zachary Deretsky]
Thanks, Peter. Actually the "Programming Perl" camel book lists this
under "Universal Blunders" on page 529. I had to discover this myself,
but the problems did not stop there.
Here is the correct version of my scanner:
sub cons::iScan {
my(@includes);
ISCAN: while(1) {
if(/^%(include|import|extern)\s+(\w+\.)(i|ii|iic|iim|hpp)\s*$/) {
push (@includes, "$2$3");
};
last ISCAN if(!($_ = <scan::quickscan::SCAN>));
}
close(scan::quickscan::SCAN);
@includes
};
Two issues are worth noting:
1. Filehandle is not a variable as the authors of "Perl Cookbook" point
out in a cloudy discussion in chapter 7.0. It is best to pass it
in a variable, say $fHandle = *SCAN; The book also mentions that
filehandles live in packages, so one should use complete
scan::quickscan::SCAN.
2. $_ which is implicitly passed as the argument to the (user written)
scanner is not the same as $_ inside this scanner, hence the
assignment in the last if clause.
Here is the relevant cons calling code:
return () unless open(SCAN, $file->rpath);
while(<SCAN>) {
push(@includes, grep($_ ne '', &$code));
}
close(SCAN);
To spare other users much suffering I plea to replace it with simple
interface:
@includes = &code($file->rpath);
The user function should open the file, close it and return a list of
include files. What could be more simple? Am I missing something?
Actually, complete solution should associate a scanner with file
extension: if my scanner for .i files returns an .hpp file, then .hpp
scanner should be called for that.
My other issues are still unresolved:
PATH for QuickScan and variables in Depends and Command methods.
Where are you, Steven? SOS!
Thanks, Zach.