Today's exercise: let the program, which is really a module with a run() mehtod, figure out what to do based on how I call it. Not using semicolons is just a bonus feature.
sub run
{
$_[0]->new->${
\(do {
if( defined $ENV{ REQUEST_METHOD } ) { 'as_html' }
elsif( -t STDIN ) { 'as_text' }
else { 'as_file' }
})
}
}
file (Score:2)
Re:file (Score:2)
STDIN or STDOUT (Score:2)
-t STDIN a bit of an odd criterium to decide what kind of output to get. I often run programs from the command line, that doesn't mean I want interactive output. Or on the contrary, it's not because my source comes from a file, that it means I want it to go to a file.In short, I'd rather use-t STDOUTto decide on kind of output instead. I imagine thatlsbehaves this way.If you want to override it, there's always command line switches.