CoderZone.org

Category: >> Perl Code >> Output To STDOUT Or A File Bookmark and Share

<< lastnext >>

Snippet Name: Output To STDOUT Or A File

Description: FileHandle is deprecated in favor of IO. This is some example code that shows how to write to either STDOUT or a file.

Also see:
» Check If A Directory Allows File C...
» A One-liner To Get Module Version

Comment: (none)

Author: CoderZone
Language: PERL
Highlight Mode: PERL
Last Modified: December 02nd, 2010

use IO qw(File Handle);
 
my $io = do{
    if (shift){
    my $tmp = IO::Handle->new;
 
    die "open failed: $!" unless $tmp->fdopen(fileno(STDOUT),"w");
    $tmp;
    }else{
    my $tmp = IO::File->new('tmp.out', 'w');
    $tmp;
    }
};
 
$io->print("Sample text output...\n");
 
 
There haven't been any comments added for this snippet yet. You may add one if you like.  Add a comment 
© coderzone.org | users online: 15