in reply to Getopt, regexen, and newlines

It seems that problem is not in Getopt::Long, but in that the substitution string has to be a plain string not escape sequence when taken from outside (of the program). Escape sequence as replacement, however, does work when hard coded in the s///. Or, something like that.

The following code -- tested in genuine xterm, bash3, perl 5.8.7, and Getopt::Long 2.68 -- will put \n as itself not as a newline if i specified the -out as an escape sequence. It did the expected when i specified the replacement string as Ctrl-J.

use warnings; use strict; use Getopt::Long qw(:config gnu_compat no_ignore_case no_debug ); # Get regexen|strings for substitution. my ($in , $out); GetOptions( 'i|in=s' => \$in , 'o|out=s' => \$out) or usage(); usage() unless defined $in && defined $out; printf "in: '%s' out: '%s'\n" , $in , $out; my $text; while (<STDIN>) { $text .= $_; } chomp $text; printf "before:\n'%s'\n" , $text; $text =~ s/$in/$out/g; printf "after:\n'%s'\n" , $text; sub usage { die "specify strings for -in & -out options.\n"; }

Update: For a user to be able to specify/use escape sequnce in replacement, use a hash, somthing like the last message in Regular Expression To Match Escape Sequences thread.

- Parv