in reply to Re: In place search and replace with a hash
in thread In place search and replace with a hash
open FH, "<infile.txt" or die $!; open OUT, ">outfile.txt"; while (<FH>) { if (/(\S+):(\S+).*\n/) { $var1 = "$1"; $var2 = "$2"; print OUT "$var1_$var2\n" } elsif (/(.*)\n/) { print OUT "$1\n"; } } close FH;
This does what I want in terms of preserving the input files non matching lines, but I am still getting a "use of uninitialized value" error, one for every line in the input file:
Use of uninitialized value $var1_ in concatenation (.) or string at test_perl.pl line 42
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: In place search and replace with a hash
by AnomalousMonk (Archbishop) on Dec 28, 2014 at 04:29 UTC | |
by hkates (Novice) on Dec 28, 2014 at 04:42 UTC | |
by AnomalousMonk (Archbishop) on Dec 28, 2014 at 05:33 UTC | |
by hkates (Novice) on Dec 28, 2014 at 21:22 UTC | |
|
Re^3: In place search and replace with a hash
by AnomalousMonk (Archbishop) on Dec 28, 2014 at 05:02 UTC |