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?