Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > reg exp

Reply
Thread Tools

reg exp

 
 
Ken Chesak
Guest
Posts: n/a
 
      08-26-2004
Perl scipt is formatting text for HTML page. It changes things like
an & to &amp. But should not change &nbsp. It uses \ as an escape
character. So \&nbsp will become &nbsp. 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.
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Help needed with reg exp please Aristotle Perl 4 09-04-2004 05:38 PM
reg exp Ken Chesak Perl 5 09-01-2004 12:27 PM
Reg Exp Help PerlE Perl 0 01-30-2004 06:15 AM
Newbie-Reg Exp psk Perl 2 01-19-2004 10:30 PM
Reg exp: matching relative path only. Andrew Rowland Perl 0 08-01-2003 11:14 PM



Advertisments