K
Ken Chesak
Perl scipt is formatting text for HTML page. It changes things like
an & to &. But should not change  . It uses \ as an escape
character. So \  will become  . The final results are
correct, but is there a better way to do this?
Input file test.txt
\HOME & \ BORN \& FREE BORN FREE ' \' HELP " \" w\\\\\\\w
1st change
1a= \HOME & \ BORN \& FREE BORN FREE '' \' HELP " \"
w\\\\\\\w
2nd changes
1b= HOME & BORN & FREE BORN FREE '' ' HELP " "
w\\\w
#!/usr/local/bin/perl5
#
%encode = ( '&' => '&',
'"' => '"',
'\'' => '\'\'' );
$data = `cat test.txt`;
print "Oa= $data\n";
$data =~ s/(?<!\\)(.)/defined($encode{$1})?$encode{$1}:$1/eg;
print "1a= $data\n";
$data =~ s/(\\)(.)/$2/g;
print "1b= $data\n";
This is perl, v5.8.0 built for PA-RISC2.0 On HP-Unix.
an & to &. But should not change  . It uses \ as an escape
character. So \  will become  . The final results are
correct, but is there a better way to do this?
Input file test.txt
\HOME & \ BORN \& FREE BORN FREE ' \' HELP " \" w\\\\\\\w
1st change
1a= \HOME & \ BORN \& FREE BORN FREE '' \' HELP " \"
w\\\\\\\w
2nd changes
1b= HOME & BORN & FREE BORN FREE '' ' HELP " "
w\\\w
#!/usr/local/bin/perl5
#
%encode = ( '&' => '&',
'"' => '"',
'\'' => '\'\'' );
$data = `cat test.txt`;
print "Oa= $data\n";
$data =~ s/(?<!\\)(.)/defined($encode{$1})?$encode{$1}:$1/eg;
print "1a= $data\n";
$data =~ s/(\\)(.)/$2/g;
print "1b= $data\n";
This is perl, v5.8.0 built for PA-RISC2.0 On HP-Unix.