in reply to Re^3: Make select apply to modules as well
in thread Make select apply to modules as well

Ok, what is happening is that the default filehandle seems to be changed inside my module as it should UNTIL I make a call to another subroutine which does an in-place edit of a file.

Does changing $^I(which I do for the in-place edit) screw anything up?

Thanks.

  • Comment on Re^4: Make select apply to modules as well

Replies are listed 'Best First'.
Re^5: Make select apply to modules as well
by tilly (Archbishop) on Dec 05, 2004 at 22:11 UTC
    I believe that you have correctly identified the problem.

    This is documented, but obscurely. If you check in perlvar you'll find that $^I is the current value of the in-place edit. If you check in perlrun you'll find that -i calls select.

    I would suggest avoiding $^I and writing the code that it saves for you. Alternately call select before setting $^I to get the currently selected filehandle, and then call select when the edit is done so that $^I and select play nice with each other.

      Thanks bro. After looking some more I realized it probably does affect something because when doing the in-place edit a print without specifying a filehandle prints to the file. I am just going to save the filehandle before I do the in-place edit and then restore it.

      Thanks again.

Re^5: Make select apply to modules as well
by gaal (Parson) on Dec 06, 2004 at 07:35 UTC
    Glad you found the problem. Consider using Tie::File as a practical alternative if you're doing in-place editing. (In some cases it may not be appropriate -- read the docs -- but for many cases, it is.)