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

The condition is not "dense".

I didn't say it was dense. What does that even mean? At what point does something become dense? How can you claim it is or isn't dense?

I said the "condition is so dense you missed that it devolves into an infinite loop of prints and warns." You tried to jam so much into a single expression that you got the expression wrong. Worse, and maybe even more importantly, it's very hard to notice that it's wrong because it's so dense. I only noticed when I rewrote your code.

Works fine for me

How would you know? You didn't try giving EOF or an error. The fact that your code doesn't handle this immediately stood out after a rewrite.

I am sure that there are many Monks who will disagree with style issues!

Sure, but when it's so hard to read that errors crop in, and when the other alternative makes the error obvious, we start leaving the realm of subjectiveness and entering the realm of objectiveness.

Also, it leaks the $line variable to the surrounding scope.

Seeking work! You can reach me at

Replies are listed 'Best First'.
Re^6: $_ not set in while <>
by LanX (Sage) on Jun 09, 2021 at 14:15 UTC
    For those wondering:
    • Misunderstanding 1:


      • Having relatively high density.
      • Slow to comprehend; of low intelligence.

    • Misunderstanding 2:
      Marshall was only attempting to read from the keyboard (and misunderstanding the OP)

      That's why he didn't care about checking defined for the line, since undef is a way to indicate EOF for files.

      But the special power of while(<>) is that he could call it on a file in @ARGV for testing those manual inputs

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

      What are you talking about. We were both discussing density, and we were both talking about a terminal (or at least didn't exclude it).

      Perhaps you think a terminal can't return EOF? Yet that's a common occurrence. I didn't say those things you tried to put in my mouth cause I didn't mean those things.

      A program that fails to handle a common occurrence by going into an infinite loop is bad, and a style that makes this kind of error easy and hard to notice is not that great. Simple as that.

      Seeking work! You can reach me at