Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Append to file or create file depending on input filename.

by bellaire (Hermit)
on Nov 20, 2009 at 13:36 UTC ( [id://808431]=note: print w/replies, xml ) Need Help??


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!

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://808431]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2024-04-20 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found