Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: $_ not set in while <>

by LanX (Sage)
on Jun 09, 2021 at 12:35 UTC ( #11133687=note: print w/replies, xml ) Need Help??


in reply to Re^2: $_ not set in while <>
in thread $_ not set in while <>

Hi

> In the above, a "my" variable cannot be defined and be used within the same comma statement or logical "and" statement, hence the "my $line;" before the loop conditional.

In that case I'd prefer the c-style for(;;) loop ...

update

from https://perldoc.perl.org/perlsyn#For-Loops plus added my logic

    for (my $i = 1; $i < 10; $i++) { ... }
    is the same as this:
    { my $i = 1; while ($i < 10) { ... } continue { $i++; } }

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11133687]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (1)
As of 2021-10-23 02:56 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My first memorable Perl project was:







    Results (86 votes). Check out past polls.

    Notices?