how to interpolate html entities easily (HOWTO) (full text of Entitize.pm)

[prev] [thread] [next] [Date index for 2005/04/20]

From: David Nicol
Subject: how to interpolate html entities easily (HOWTO) (full text of Entitize.pm)
Date: 16:52 on 20 Apr 2005
the following snippet allows stating things like=20

      use Entitize;
      ...
      print qq{<input name=3D"data" value=3D"$Entitize{$old_data}">\n};
      ...=20
      print qq{The full text of the block is <pre>$Entitize{$block}</pre>\n=
};

directly, rather that using the generating functions of CGI.pm, or making
intermediate variables to hold the results of encode_entities calls. (nothi=
ng
against them, but here's Another Way To Do It)

cat > lib/Entitize.pm <<EOF
     package Entitize;
     use HTML::Entities;
     use Tie::Function;
     tie my %Entitize, 'Tie::Function' =3D> \&encode_entities;
     sub import{ *{caller().'::Entitize'} =3D \%Entitize };
     1;
EOF

These three lines are too small to bother wrapping up in Entitize.pm
and publishing to CPAN, in my opinion.  You want it, it will copy and
paste into your cygwin bash or xterm.  Opinions are subject to change.


--=20
David L Nicol
"Oh, shit." -- Jane Fonda

how to interpolate html entities easily (HOWTO) (full text of Entitize.pm)
David Nicol 16:52 on 20 Apr 2005

Generated at 09:30 on 27 Apr 2005 by mariachi v0.52