On Nov 1, 10:49 pm, [EMAIL PROTECTED] (Phillip Gonzalez) wrote: > I'm trying to print stdout to a file, then switch back to the default > standard out so that it prints to the screen. This script takes a > list of ip's and does a reverse lookup on them, it then saves the > output to "reverse.txt". > > Here's my code: > > #!/usr/bin/perl > > use strict; > use warnings; > > print "Enter the file you want to perform a reverse lookup on:\n"; > > my $file_open = <STDIN>; > open (STDOUT,">reverse.txt"); > open(DEVFILE, "$file_open") or die "Can't open file dude!: $!"; > my @dev_ip=<DEVFILE>; > foreach my $ip(@dev_ip) { > system("host -W 1 $ip") > } > close(DEVFILE); > close(STDOUT); > print "Your ouput has been saves as reverse.txt in the > current directory\n"; > ###### I want to print this line back to > STDOUT but since I redirected it above with "open > (STDOUT,">reverse.txt") I can't figure out how to.
There's a couple ways to handle this. One is to localize your change to *STDOUT so that it goes back to what it was when the block ends: { local *STDOUT; open (STDOUT,">reverse.txt"); system("whatever"); } print "Back to the screen."; The more obvious and more correct way is just to redirect the child process's STDOUT, and not your own. Don't open STDOUT to any other file at all: system("whatever > reverse.txt"); print "To the screen"; Paul Lalli -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/