in reply to autoconverting print to say

I convert this code by hand (or a Vim macro) only when I can verify that it's correct. Consider the case of a modified $\, for example; if you substitute print for say then, you'll change the behavior of the program.

Replies are listed 'Best First'.
Re^2: autoconverting print to say
by ikegami (Patriarch) on Nov 13, 2009 at 23:07 UTC

    Chances are print "...\n" isn't used in conjunction with $/.

    I'd look for $/ to make sure it's not going to interfere, then use something like

    while (<>) { s/print(.*?)\\n("\)?;)/say$1$2/; s/(say.*?)[.,]\s*""(\)?;)/say$1$2/; print; }

    Then, I'd do a quick diff between the original and the modified file to verify the change. Don't forget to look for missed occurrences, including local $\ = "\n"; print "foo";