Pathologically Eclectic Rubbish Lister | |
PerlMonks |
Redirect Subroutine Outputby spickles (Scribe) |
on Aug 26, 2009 at 15:41 UTC ( [id://791373]=perlquestion: print w/replies, xml ) | Need Help?? |
spickles has asked for the wisdom of the Perl Monks concerning the following question:
Monks -
I wrote a subroutine to write some commands to the screen for a user to verify the output. If the user selects 'YES' to then process those commands, they'll be delivered to a switch via telnet. So the first time through the subroutine I print to the screen. How can I make my code efficient to use the same subroutine again but this time print to a file? To print to the screen I just neeed to call 'print "blah\n";', but to print to a file I need 'print MYFILE "blah\n";'. I could pass a variable to the subroutine and say something like
Again, I'm trying to find a way to perform this efficiently so I don't have to write these if statements and lines more than once to make efficient code. Can I call the subroutine normally the first time to print to the screen, and call it a second time with a pipe or redirect to have those print functions go to a file? Regards, Scott
Back to
Seekers of Perl Wisdom
|
|