I’m curious if I can toggle between printing to STDOUT or STDERR based on some value or inline expression (without using an if statement).
print ($someFlag ? STDOUT : STDERR) "hello world!"
Obviously, that syntax doesn’t work.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
I think this will do what you want:
A similar example can be seen in the documentation for print. Use typeglobs so that it will run under
use strict.Another strategy is to define your own printing function that will behave differently, depending on the value of
$someFlag.