John Dillon wrote: > > According to > http://vipe.technion.ac.il/~shlomif/lecture/Perl/Newbies/lecture2/argv.html > the following program will do ...whatever (make a backup of files) and it > takes the file specified at the command line. I guessed from this that one > has a .pl file with the following script, execute it at c: by typing its > name and then the program stops and asks you what file you want to specify. > But this does not happen. So how do you get the filename into the script?
You type in the file name after the program name: C:\> program.pl filename > use strict; > > my $filename = $ARGV[0]; The @ARGV array contains the contents of the command line after the program name. C:\> program.pl -f filename 2 3 # $0 contains 'program.pl' or 'c:\program.pl' # #ARGV[0] contains '-f' # #ARGV[1] contains 'filename' # #ARGV[2] contains '2' # #ARGV[3] contains '3' > open I, "<".$filename; > open O, ">".$filename.".bak"; You should _ALWAYS_ verify that the files opened correctly. open I, "<$filename" or die "Cannot open $filename: $!"; open O, ">$filename.bak" or die "Cannot open $filename.bak: $!"; And, since you are on Windows, you may want to binmode the files: binmode I; binmode O; > print O join("",<I>); You don't need a join() in there. print O <I>; However that will read the entire file into memory before printing it out. This is more memory efficient: print O while <I>; > close(I); > close(O); John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]