Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Simple Example Opening Files from Command Line

Status
Not open for further replies.

robdunfey

Technical User
Apr 26, 2002
110
GB
Hi,

I am trying to do something very simple, but having never used perl before I am having significant trouble. I want to open three new files, I want the user to specify the name of the files at the command line when they type in the name of the perl script to execute. I am sure this must be possible but dont know where to start, if someone could give me an example or point me in the direction of a sample it would be very much appreciated,

Kind Regards,

Rob
 
Hi

Not too sure I understand exactly what you require but this might help

If you want to specify some files to open at the command line try the following

perl open3files.pl file1.pl file2.pl file3.pl

The 'file1.pl file2.pl file3.pl' after the perl file to open are held in an environment variable @ARGV

print "@ARGV";

You could then split this up and work on each file in turn

Hope this is of some use!
 
Hi,

Thanks for the reply. Sorry if I was not clear. I want to access parameters entered at the command line in the perl script, I see what you mean about using @ARGV - and it works, but it is no use if I want to pass the name of a file with a space in it as a parameter. Is this the accepted way of accessing parameters specified at the command line?

Thanks again,

Rob
 
It should work if you put your arguments in quotes -

C:\>perl test.pl "arg 1" "arg 2" "arg 3"
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top