reg exp

Discussion in 'Perl' started by Ken Chesak, Aug 26, 2004.

  1. Ken Chesak

    Ken Chesak Guest

    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.
     
    Ken Chesak, Aug 26, 2004
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andrew Rowland

    Reg exp: matching relative path only.

    Andrew Rowland, Aug 2, 2003, in forum: Perl
    Replies:
    0
    Views:
    1,146
    Andrew Rowland
    Aug 2, 2003
  2. psk

    Newbie-Reg Exp

    psk, Jan 16, 2004, in forum: Perl
    Replies:
    2
    Views:
    1,367
    Gunnar Hjalmarsson
    Jan 19, 2004
  3. PerlE

    Reg Exp Help

    PerlE, Jan 30, 2004, in forum: Perl
    Replies:
    0
    Views:
    507
    PerlE
    Jan 30, 2004
  4. Ken Chesak

    reg exp

    Ken Chesak, Aug 30, 2004, in forum: Perl
    Replies:
    5
    Views:
    651
  5. Aristotle

    Help needed with reg exp please

    Aristotle, Sep 4, 2004, in forum: Perl
    Replies:
    4
    Views:
    490
    Gunnar Hjalmarsson
    Sep 4, 2004
Loading...

Share This Page