in reply to Re: Redefining chomp()
in thread Redefining chomp()

This was exactly what I was looking for. I don't anticipate that it will break anything that I am doing. Though, testing will be in order. Modifying $/ global would, indeed, be a very bad thing to do. I knew this was a possible solution, but i would have rather done it locally to each chomp().

Replies are listed 'Best First'.
Re: Re: Re: Redefining chomp()
by dragonchild (Archbishop) on Mar 24, 2004 at 14:58 UTC
    If that's all you wanted to do, a simple perl -pi -e 's/chomp([^;]*);/{local $/="\r\n";chomp$1;}/gm;' <your files here> would have sufficed ... wouldn't it?

    ------
    We are the carpenters and bricklayers of the Information Age.

    Then there are Damian modules.... *sigh* ... that's not about being less-lazy -- that's about being on some really good drugs -- you know, there is no spoon. - flyingmoose

Re: Re: Re: Redefining chomp()
by amw1 (Friar) on Mar 24, 2004 at 15:18 UTC
    Wouldn't this be a good place to use local? Something like
    { local $/ = "\n\r"; chomp; }
    protect the global state of $/ and let you deal with changing it's behavior right before the chomp. The scope could be increased until you've captured all of your chomp calls. Any new chomps you write, unless they're in the same scope as the local call would use the default value of $/
    code is untested.
      If he doesn't want to search the entire code to replace calls to chomp, it's likely that he wouldn't want to locally redefine $/ by putting blocks around each chomp statement.