pidloop has asked for the wisdom of the Perl Monks concerning the following question:
Oh great Monks, I have a simple (I think) question of understanding.
I want to read a file until I find a line containing a pattern. I tried this:
but it complained about $_ undefined in m// match. So I then made the assignment to $_ explicit like so and it works great:while (<> and !/pattern/) {}
I am surprised by the need of doing this and would like to understand why. Thank you all!while (defined($_ = <>) and !/pattern) {}
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: $_ not set in while <>
by LanX (Saint) on Jun 06, 2021 at 00:57 UTC | |
by Marshall (Canon) on Jun 06, 2021 at 02:59 UTC | |
by LanX (Saint) on Jun 06, 2021 at 12:46 UTC | |
by ikegami (Patriarch) on Jun 06, 2021 at 04:15 UTC | |
by Marshall (Canon) on Jun 06, 2021 at 05:02 UTC | |
by kcott (Archbishop) on Jun 06, 2021 at 06:28 UTC | |
| |
by ikegami (Patriarch) on Jun 09, 2021 at 05:57 UTC | |
| |
by LanX (Saint) on Jun 09, 2021 at 12:35 UTC | |
by Anonymous Monk on Jun 08, 2021 at 17:06 UTC |
Back to
Seekers of Perl Wisdom