if (/(\S+):(\S+).*\n/) { $var1 = "$1"; $var2 = "$2"; print OUT "$var1_$var2\n" } elsif (/(.*)\n/) { print OUT "$1\n"; } }
Ok, once you get that working (i.e., fix $var1_ problem), try reducing the big if-statement to a single s/// substitution (untested):
s{ (\S) : (\S) }{${1}_$2}xmsg;
(which just replaces every : with an _), followed by a print of the (possibly altered) line (held in $_ in this code) to the output filehandle.
Update: This reply may have been superseded by your intervening post, but what the heck...
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: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |