Dear Monks - I am novice asking for help or advice please;
To modify a text file by adding one extra line spacing between each line, I initially hardcoded the name of target file... 3.txt into my code.
How to revise so that ANY file can be used (ie. perl myprogram.pl anyfile.txt) from the command line?
I have started to read about IO::Handles ... would you recommended that or please say what would be a better method for this problem?
open(PAGE,"3.txt") || die "I can't open yourfile.txt"; @File =<PAGE> ; #store the contents of the file into array close(PAGE); $Ctr = 0; foreach (@File){ # loop through file { $_ = $_ . "\n" #add extra newline to each line } $Ctr = $Ctr+1; #increment through the array } #end foreach open(PAGE,">3.txt") || die "I can't open yourfile.txt"; #write the a +rray contents print PAGE @File; close(PAGE);
In reply to IO::Handles ... any good? by blowupp
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |