in reply to flag function
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".print "start\n" if (grep {/test/}<TEST>);
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.while (<TEST> and !$flag){} #UPDATE---see below discussion!
Update:
oh, I see now: open TEST,"@ARGV[0]"; that would be flagged as an error if you have use strict; use warnings; in effect. Correct is $ARGV[0].
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: flag function
by choroba (Cardinal) on Jul 12, 2018 at 07:23 UTC | |
by Marshall (Canon) on Jul 13, 2018 at 16:29 UTC |