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' } }) } }
Re:file
brian_d_foy on 2004-05-08T23:00:25
I don't know what kind of file it is. Right now it's a placeholder method that catches anything that falls through.
-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 STDOUT
to decide on kind of output instead. I imagine that ls
behaves this way.
If you want to override it, there's always command line switches.