P is for Practical | |
PerlMonks |
Re^3: (Perl 5.10.1 or before)What does $_ refer to here?by Athanasius (Archbishop) |
on Jun 10, 2019 at 13:32 UTC ( [id://11101198]=note: print w/replies, xml ) | Need Help?? |
Hello hghosh, how would I use $line directly in the while condition? And what makes that better than declaring it as I did? I think LanX is recommending something along these lines:
which is simpler and clearer. Also, if I left $_ as it is in the second, strictured code block, it would refer to the same $_ as the first block of code, right? Not sure which blocks you’re referring to; but, just to be clear, $_ refers to the “current” (i.e., the most closely related) syntactic construct that sets it. For example:
produces:
— showing that there are actually as many independent instances of $_ (two, in this case) as the scoping requires. Hope that helps,
In Section
Seekers of Perl Wisdom
|
|