in reply to Testing a subroutine with STDIN
Similar to the external file approach, for simple tests, I've gotten some mileage out of just pointing STDIN to DATA.
use warnings; *STDIN = *DATA; print while <STDIN>; __DATA__ Hello world Once upon a time... How now brown cow
Another approach that doesn't need an external file is to use IO::String to create an in-memory file and alias STDIN to that. By directly changing the contents of the underlying scalar, you can control what will next be read from the in-memory file.
-xdg
Code written by xdg and posted on PerlMonks is public domain. It is provided as is with no warranties, express or implied, of any kind. Posted code may not have been tested. Use of posted code is at your own risk.
|
|---|