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!

filename as argument 1

Status
Not open for further replies.

woobie

Technical User
Sep 25, 2000
1
US
I'm using Perl on UNIX. How do I make my program take
a filename as an argument? In other words, I have a
program that operates on an existing file and I want to
be able to type in my program name followed by a space followed by a file name and have my program operate on that file. I don't want to have to prompt the user for the filename.

Thanks. [sig][/sig]
 
if you call your Perl script like this:
Code:
perl_script.pl the_data_file
You can get at the filename on the command line like this:
Code:
my $fname = shift || die "No filename on command line\n";
As Russ says, the command line arguments are stored in @ARGV, shift returns the first element of @ARGV and then removes it from @ARGV [sig]<p>Mike<br><a href=mailto:michael.j.lacey@ntlworld.com>michael.j.lacey@ntlworld.com</a><br><a href= Cargill's Corporate Web Site</a><br>Making mistakes, so you don't have to. &lt;grin&gt;[/sig]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top