Slash Boxes
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Saturday May 08, 2004
03:38 PM

Let the script figure it out

[ #18676 ]

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
        \(do {
            if( defined $ENV{ REQUEST_METHOD } ) { 'as_html' }
            elsif( -t STDIN )                    { 'as_text' }
            else                                 { 'as_file' }

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
More | Login | Reply
Loading... please wait.
  • I know what plain text look like and I'm familiar with HTML. But what kind of "file" is that?
    • I don't know what kind of file it is. Right now it's a placeholder method that catches anything that falls through.
  • I find -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.