From:                   "Angus Laycock" <[EMAIL PROTECTED]>
> I want to print messages from a script to either STDOUT or STDERR
> depending on a value of a variable. I want to control where I send the
> print statements to. Can I do something like this or are there other
> ways to control the target I send my message to. I'm hoping there are
> lots of other ways.
> 
> if ($out) { $whereitsggoing = STDERR } else { $whereitsggoing = STDOUT
> }
> 
> print $whereitsgoing "My message\n";

Either

        if ($out) { 
                *STDSOME = STDERR 
        } else { 
                *STDSOME = STDOUT
        }

        print STDSOME "My message\n";

or

        use FileHandle;
        
        my $FH;
        if ($out) { 
                $FH = \*STDERR 
        } else { 
                $FH = \*STDOUT
        }

        print $FH "My message\n";

or

        if ($out) { 
                open STDSOME, '>&STDERR';
        } else { 
                open STDSOME, '>&STDOUT';
        }

        print STDSOME "My message\n";

or

        use FileHandle;
        
        my $FH;
        if ($out) { 
                open $FH, '>&STDERR';
        } else { 
                open $FH, '>&STDOUT';
        }

        print $FH "My message\n";

In the first two solutions when you change where the 
STDOUT/STDERR goes, the STDSOME (or $FH) will "change" as 
well, in the last two it'll remain unaffected.

HTH, Jenda

=========== [EMAIL PROTECTED] == http://Jenda.Krynicky.cz ==========
There is a reason for living. There must be. I've seen it somewhere.
It's just that in the mess on my table ... and in my brain.
I can't find it.
                                        --- me

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to