http://qs321.pair.com?node_id=349159

perlcgi has asked for the wisdom of the Perl Monks concerning the following question:

I'm processing very large text files of delimited records, and localizing $/ to be my delimiter works great.
{local $/ = "DELIMITER"; while( <FILE> ){ do_this(); do_that(); do_the_other(); } }
However, I don't like having $/ altered for the scope of the entire while-loop 'cos that's pretty much my whole program and it could have consequences for the subroutines within the loop. I'm seeking a nice idiom to return it to its previous value, after it has done it's thing, for each iteration. Suggestions much appreciated.

Replies are listed 'Best First'.
•Re: Seeking an idiom for localizing $/
by merlyn (Sage) on Apr 29, 2004 at 15:29 UTC
      Thanks once again Randal.
      A grateful perlcgi makes mental note to purchase his own copy of Learning Perl Objects, References & Modules and wonders if this idiom is well know, or just an off-the-cuff creation of the wizard.
        wonders if this idiom is well know, or just an off-the-cuff creation of the wizard
        Just synthesized from smaller idioms. It's not that I'm necessarily a wizard: I just remember lots of little things that work, and put them together in interesting ways.

        -- Randal L. Schwartz, Perl hacker
        Be sure to read my standard disclaimer if this is a reply.

    A reply falls below the community's threshold of quality. You may see it by logging in.
Re: Seeking an idiom for localizing $/
by ihb (Deacon) on Apr 30, 2004 at 00:25 UTC
    Just don't forget to localize $_ too.