[boulder.pm] break a while(<F>) and better grep?
Randall Fowle
bmozart at frii.com
Sun May 14 00:26:29 CDT 2000
On Sat, 13 May 2000, Robert L. Harris wrote:
> Part of the problem is I want it to break out of the while at the first
> time it finds $string, but not the loop that the while is in. Will
> a "break" do this clean? Something else?
The keyword "last" works like "break" does in C:
while(<File>) {
if (<$String>) {
do stuff;
last;
}
}
This will take you out of the while(<File>) loop without taking you out
of a loop that contains this code.
> Is there a faster way to grep a string out of a file, without actually
> doing a system('grep')? I just need to know if the string is in the
> file.
System will at least tell you if the string is in the file, even if it
does spawn a whole new process. As far as I know, your only alternative
is to traverse the file and try to match the string to each line.
-Randy.
will skip the reference between spawning processes and Mother's Day
More information about the Boulder-pm
mailing list