in reply to Append to file or create file depending on input filename.

When you use a shell command like:
C:\>perl script.pl >outfile
The argument >outfile never reaches the Perl script. The shell interprets it as you asking to execute perl script.pl and send its output to outfile. As far as Perl knows, there are no command-line arguments to script.pl. If you want to optionally use the filename to change your output behavior, you'll have to do so without using the > character as the first character of your argument.

Replies are listed 'Best First'.
Re^2: Append to file or create file depending on input filename.
by pKai (Priest) on Nov 20, 2009 at 13:48 UTC

    I was wondering the same.

    To (ab)use 2-arg open in the way the OP describes, he has to do some trickery like:

    C:\>perl script.pl ">outfile" C:\>rem Or C:\>perl script.pl ^>outfile

    which will effectively hide the output redirect from the cmd and result in an $ARGV[0] containing >outfile.

Re^2: Append to file or create file depending on input filename.
by markuhs (Scribe) on Nov 20, 2009 at 13:42 UTC
    Correct, the usage was wrong. I missed out the double quotes...
    Thanks for pointing that out!