print OUT "$var1_$var2\n"
The '_' (underscore) character is a valid identifier, i.e., variable name, symbol. Therefore, the two variables you're using are $var1_ (note trailing _), which is not defined, and $var2, which is. Had you been using strictures as well as warnings, Perl would not have allowed this little oversight (see strict and warnings). The proper way to write this statement (if you really need the _) is
print OUT "${var1}_$var2\n";
(Note that I've added a ; at the end; the absence of this statement terminator caused no syntactic problem in the given code, but would have eventually — trust me.)
open FH, "<infile.txt" or die $!;
open OUT, ">outfile.txt";
Update: You seem to be back-sliding. In contrast to your OPed code, this code uses global filehandles, two-parameter open, and does not check the status of the output file open. Tsk, tsk! IMHO, the OPed code used better practices.
Give a man a fish: <%-(-(-(-<
In reply to Re^3: In place search and replace with a hash
by AnomalousMonk
in thread In place search and replace with a hash
by hkates
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |