in reply to Re: flag function
in thread flag function

while (<TEST> and !$flag){}

Just a note: if you want to do something with the line read from the filehandle (and you probably want to set the flag at least), you can't just use <TEST>: it only works in a simple while, not in a more complex condition.

1 while defined ($_ = <>) and not $seen = /test/; say $seen;

($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

Replies are listed 'Best First'.
Re^3: flag function
by Marshall (Canon) on Jul 13, 2018 at 16:29 UTC
    You are correct!
    I typed that in quicky from a cut-n-paste of OP's code without actually running a piece of code.

    For those interested, here are some redacted code examples to show what happens:

    while (<DATA> and !$flag){print;} error is: Use of uninitialized value $_ in print at C:\testwhile.pl li +ne 8, <DATA> line 1. while ($_=<DATA> and !$flag){print;} error is: Value of <HANDLE> construct can be "0"; test with defined() +at C:\testwhile.pl line 6. while (defined($_=<DATA>) and !$flag) no error
    I was impressed the first time that I saw error msg #2! Perl tells you exactly what to do and why. Impressive!
    Of course these are examples of why to always use strict; use warnings;!

    Update: A recent post my me that demo's this: Re: Search between pattern and append