in reply to run away ?

If your going to change $/ use local $/ = "new value";.

Your script won't loop forever, nor will a while loop. Your computer won't blow up either. :-)

Have a look at perlvar (search for $INPUT_RECORD_SEPARATOR) to get the full details.

Here's a test:

#!perl use 5.12.0; use warnings; local $/ = "1313"; while (<DATA>) { say qq{Found line: $_}; } __DATA__ qwerty qwerty qwerty qwerty qwerty qwerty

Which outputs:

$ strange_in_rec_sep.pl Found line: qwerty qwerty qwerty qwerty qwerty qwerty

Adding 1313 to the data:

__DATA__ qwerty qwerty qwerty 1313 qwerty qwerty qwerty

The output becomes:

$ strange_in_rec_sep.pl Found line: qwerty qwerty qwerty 1313 Found line: qwerty qwerty qwerty

Thanks for your amusing post. I had a good chuckle. :-)

-- Ken

Replies are listed 'Best First'.
Re^2: run away ?
by toniax (Scribe) on Nov 06, 2010 at 21:06 UTC
    I like to make people laugh even if it wasn't intended. I have another strange piece of code to present sometime soon You should like this one lol

      I had visions of the dreaded double-13 bug ravenously devouring computer resources until the hardware exploded. :-)

      -- Ken

Re^2: run away ?
by Jim (Curate) on Nov 07, 2010 at 21:12 UTC
    If your going to change $/ use local $/ = "new value";.

    Why?

    I ask because this is one of those cases I struggle with. Sometimes I use local $INPUT_RECORD_SEPARATOR = "some string"; in Perl scripts (not modules), sometimes I don't. I feel like I should localize the variable, but doing so also seems inert. Why should I care about the scope that doesn't exist outside the universe of my standalone Perl script? Isn't local just needless noise here?

    I should add that I usually set this built-in variable outside any blocks within my scripts unless I have a specific reason to do otherwise (and I usually don't).

      Because it's a useful default behaviour that doesn't cost a lot and doesn't add much noise when it's not required, but can save a huge amount of pain when it is required. Think of it as a good habit like using strictures, three parameter open and all those other good habits that just naturally flow off the ends of your fingers or are part of your standard boilerplate.

      True laziness is hard work

        I accept that. I do a lot of things in my Perl scripts based on the rationale you described, many of which I learned from Perl Best Practices.

        local: You're in!