#!/usr/bin/perl
use File::Copy;
if ($ARGV[0] eq "-") {
    open dest, ">", $ARGV[1] or do {
        print STDERR "Unable to open destination 2 ($ARGV[1]) for pipe $!\n";
        exit 1;
    };
} elsif ($ARGV[1] eq "-" ) {
    open dest, ">", $ARGV[0] or do {
        print STDERR "Unable to open destination 1 ($ARGV[0]) for pipe $!\n";
        exit 2;
    };
} else {
    if (length $ARGV[0] && length $ARGV[1]) {
        copy $ARGV[0], $ARGV[1] or do {
            print STDERR "Unable to copy from $ARGV[0] to $ARGV[1] : $!\n";
            exit 3;
        };
    } else {
        copy *STDIN,*STDOUT or do {
            print STDERR "Unable to copy from StdIn to StdOut : $!\n";
            exit 4;
        };
    }
    exit 0;
}
#copy \*STDIN, dest or do {
#    print STDERR "Unable to copy from stdin to $dest: $!\n";
#    exit 5;
#};
#
#
while(<STDIN>) {
    print dest or do {
        print STDERR "Unable to copy from stdin to dest: $!\n";
        exit 5;
    };
}