blowupp has asked for the wisdom of the Perl Monks concerning the following question:
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);
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: IO::Handles ... any good?
by toolic (Bishop) on Mar 22, 2009 at 18:30 UTC | |
by blowupp (Novice) on Mar 22, 2009 at 18:41 UTC | |
|
Re: IO::Handles ... any good?
by gulden (Monk) on Mar 22, 2009 at 18:38 UTC | |
by jwkrahn (Abbot) on Mar 22, 2009 at 19:20 UTC | |
by ikegami (Patriarch) on Mar 22, 2009 at 19:25 UTC | |
|
Re: IO::Handles ... any good?
by linuxer (Curate) on Mar 22, 2009 at 18:40 UTC | |
by blowupp (Novice) on Mar 22, 2009 at 20:58 UTC | |
by linuxer (Curate) on Mar 22, 2009 at 21:11 UTC | |
by ikegami (Patriarch) on Mar 23, 2009 at 02:25 UTC | |
by gulden (Monk) on Mar 22, 2009 at 19:00 UTC | |
by linuxer (Curate) on Mar 22, 2009 at 19:11 UTC | |
by ikegami (Patriarch) on Mar 22, 2009 at 19:32 UTC |