in reply to How to handle metacharacters in input file for Perl one-liner code
Not being a windows person, I don't know if the \Q\E quotemeta that marinersk is suggesting will have problems when passed to the windows shell, but I'm fairly certain that there would be at least some risk that you might eventually need to include a character that causes some pain due to shell escaping. Thus, I beg you consider doing it the long way.
my $file = "foo.c"; rename "sample.csv", "sample.csv.bak" or die "Error backing up sample. +csv: $!"; open my $IN, "<", "sample.csv.bak" or die "Error reading sample.csv +.bak: $!"; open my $OUT, ">", "sample.csv" or die "Error writing to sample. +csv: $!"; while (defined(my $line = <$IN>)) { $line =~ s/\Q$file\E/$file,=SUM(B$x:B$y)/; print $OUT $line; }
Good Day,
Dean
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: How to handle metacharacters in input file for Perl one-liner code
by debug (Initiate) on Jul 16, 2015 at 14:12 UTC | |
by AnomalousMonk (Archbishop) on Jul 16, 2015 at 16:56 UTC | |
by Laurent_R (Canon) on Jul 16, 2015 at 16:57 UTC |
In Section
Seekers of Perl Wisdom