>Have you tried calling it as > > perl argv_test.pl cookies.txt Actually, that did work! Now, why?? It's obviously executing when called as simply: argv_test.pl cookies.txt
It doesn't really matter. I don't mind having to put perl in front of the file name. It's just confusing that it works that way and not the other... Thanks very much for the suggestion. It was so frustrating since every example/documentation assumes you can simply supply command-line arguments. (And it should be that simple.) -----Original Message----- From: Jeff 'japhy' Pinyan [mailto:[EMAIL PROTECTED] Sent: Thursday, June 03, 2004 5:30 AM To: Larry Wissink Cc: [EMAIL PROTECTED] Subject: Re: Confused about supplying command line arguments and using @ARGV On Jun 2, Larry Wissink said: >I want to supply the name of a file on the command line when executing a >script. Unfortunately, I'm getting an error that says that @ARGV is >uninitialized. > >How do you initialize @ARGV? How do you specify command line arguments? You don't initialize @ARGV. It gets whatever arguments are passed to your program. You send your program arguments by placing them after the program name. >C:\Perl\my_scripts>argv_test.pl cookies.txt Have you tried calling it as perl argv_test.pl cookies.txt I'm just curious because I don't trust Windows. >use warnings; > >#push @ARGV, "cookie.txt"; # when uncommented script works fine. > >my $name = $ARGV[0]; >print $name; > >open (INFILE, $name); >while (<INFILE>) { > print $_; >} >close INFILE; That code looks ok to me. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ CPAN ID: PINYAN [Need a programmer? If you like my work, let me know.] <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>