go ahead... be a heretic | |
PerlMonks |
comment on |
( [id://3333]=superdoc: print w/replies, xml ) | Need Help?? |
using a flag is fine. What you have is completely understandable, however your code will keep reading lines even after the flag is found. I would probably code something similar to what hippo++ did which uses last; to stop the loop once reading more lines has no useful purpose.
However, something like this is also possible if the file is "small": This would also read all of the lines in <TEST>. The scalar value of the grep is number lines containing "test". So you get one single print of "start" if any lines contain "test". Not the most efficient way, but also obvious to a Perl'er and fine if the file is "small".
Another loop construct instead of "last" could be: I would use something like that if the block of code is more than say 5 lines. Then I see that the loop will stop prematurely without having to read the body of the code and realize that there is a "last;" Of course I would name $flag to something like $test_seen.
Update: In reply to Re: flag function
by Marshall
|
|