If *ARGV is already open, then the next <> would continue reading from it before looking for the next file name in @ARGV. So you probably used <> before you called the subroutine that you described.
You could close *ARGV, but that would disrupt the other code that was already using <> to read from STDIN. So you might instead want to do local( *ARGV ) in your subroutine before you assign to @ARGV.
| [reply] [d/l] [select] |
Thank you for your help. I found the problem. I used 'readline' in another other subroutine to gather some input from STDIN, but failed to include a file handle. That routine worked fine, but apparently it did not close properly when the code exited the routine and so when I called the subroutine above, it continued to read from STDIN. The problem was fixed by changing 'readline' to <STDIN>. It appears that when I used 'readline' without a file handle, it used whatever was in $_ as a file handle and then didn't close it upon returning from the subroutine? Anyway, good lesson learned. | [reply] |