[boulder.pm] break a while(<F>) and better grep?
Jay Kominek
Jay.Kominek at colorado.edu
Sun May 14 00:35:20 CDT 2000
> while(<File>) {
> if (<$String>) {
> do stuff;
> }
> }
>
> 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?
FOO: while(1) {
BAR: while(1) {
BAZ: while(1) {
if($magic== 42) { last FOO; } # break out of top loop
if($magic==0x42) { last BAR; } # break out of middle loop
if($magic== 666) { last BAZ; } # break out of bottom loop
}
}
}
last and break should be interchangable when you're giving the name.
next <name> also exists. I believe this is discussed in the perlsyn
man page.
> 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.
undef$/;
open(FILE,"file");
$kungfu = <FILE>;
close(FILE);
if($kungfu =~ /string/) {
# do speed-elite magic here
}
- Jay Kominek <jay.kominek at colorado.edu>
Waiting is.
More information about the Boulder-pm
mailing list