in reply to Opening a file, editing, copying to another

Without trying to figure out what you are actually trying to achieve with the file manipulation, here at least is a sample the does what you seem to want for the line manipulations:

use strict; use warnings; my @lines = map {[split]} <DATA>; for my $line (@lines) { for my $wordIndex (0 .. $#$line) { substr $line->[$wordIndex], 0, 0, '$'; print join (' ', @$line), "\n"; substr $line->[$wordIndex], 0, 1, ''; } print "\n"; } __DATA__ one fish, two fish, red fish, blue fish

Prints:

$one fish, one $fish, $two fish, two $fish, $red fish, blue fish red $fish, blue fish red fish, $blue fish red fish, blue $fish

Note in particular the use of strictures (use strict; use warnings;) and the use of Perlish for loops rather than C for loops.

Note too that for sample code it is useful if the code can be run with sample data provided - a __DATA__ section helps a lot with that.


DWIM is Perl's answer to Gödel