Click here to get back home

"Escape" in perl

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
"Escape" in perl Bill H 10-16-2008
Get Chitika Premium
Posted by Bill H on October 16, 2008, 6:21 pm
Please log in for more thread options
I am using the following code to unescape html text that is coming
from flash:

sub unescape
{
my $text = shift;
$text =~ s/%(..)/pack("c",hex($1))/ge;
return($text);
}

for example it will take this text:

%3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
%2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
%2FFONT%3E

and it will convert it to this:

<FONT FACE="timesnewroman" COLOR="#000000" SIZE="20"><P
ALIGN="CENTER">Chapter Title</P></FONT>

What I am trying to figure out is how to go the other way in perl,
convert the html to an escaped format. Any hints, clues, pointers
would be appreciated

Bill H

Posted by Tim Greer on October 16, 2008, 6:45 pm
Please log in for more thread options
Bill H wrote:

> I am using the following code to unescape html text that is coming
> from flash:
>
> sub unescape
> {
> my $text = shift;
> $text =~ s/%(..)/pack("c",hex($1))/ge;
> return($text);
> }
>
> for example it will take this text:
>
> %3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
> %2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
> %2FFONT%3E
>
> and it will convert it to this:
>
> <FONT FACE="timesnewroman" COLOR="#000000" SIZE="20"><P
> ALIGN="CENTER">Chapter Title</P></FONT>
>
> What I am trying to figure out is how to go the other way in perl,
> convert the html to an escaped format. Any hints, clues, pointers
> would be appreciated
>
> Bill H

Just don't run the input through the unescape sub routine (or have one
that does and another that doesn't (and do whatever you want with the
other))? Or am I misunderstanding your problem/question?
--
Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
Industry's most experienced staff! -- Web Hosting With Muscle!

Posted by Bill H on October 16, 2008, 7:05 pm
Please log in for more thread options
> Bill H wrote:
> > I am using the following code to unescape html text that is coming
> > from flash:
>
> > sub unescape
> > {
> > =A0 =A0 my $text =3D shift;
> > =A0 =A0 $text =3D~ s/%(..)/pack("c",hex($1))/ge;
> > =A0 =A0 return($text);
> > }
>
> > for example it will take this text:
>
> > %3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3D
> > %2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
> > %2FFONT%3E
>
> > and it will convert it to this:
>
> > <FONT FACE=3D"timesnewroman" COLOR=3D"#000000" SIZE=3D"20"><P
> > ALIGN=3D"CENTER">Chapter Title</P></FONT>
>
> > What I am trying to figure out is how to go the other way in perl,
> > convert the html to an escaped format. Any hints, clues, pointers
> > would be appreciated
>
> > Bill H
>
> Just don't run the input through the unescape sub routine (or have one
> that does and another that doesn't (and do whatever you want with the
> other))? =A0Or am I misunderstanding your problem/question?
> --
> Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
> Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
> and Custom Hosting. =A024/7 support, 30 day guarantee, secure servers.
> Industry's most experienced staff! -- Web Hosting With Muscle!- Hide quot=
ed text -
>
> - Show quoted text -

Tim

Actually the problem is that I want to use perl to make a lot of
default "escaped" html for flash. Up till now I have been just using
flash to do it, but now I have about 60 templates that I need to
create and know there has to be a better way then code actionscript,
run flash, cut / paste escaped stuff into perl code, run perl to
create template, repeat.

I was thinking of using HTML::Entities, but I can't install it on the
server I am using.

Bill H

Posted by Bill H on October 16, 2008, 7:10 pm
Please log in for more thread options
>
>
>
>
>
> > Bill H wrote:
> > > I am using the following code to unescape html text that is coming
> > > from flash:
>
> > > sub unescape
> > > {
> > > =A0 =A0 my $text =3D shift;
> > > =A0 =A0 $text =3D~ s/%(..)/pack("c",hex($1))/ge;
> > > =A0 =A0 return($text);
> > > }
>
> > > for example it will take this text:
>
> > > %3CFONT%20FACE%3D%22timesnewroman%22%20COLOR%3D%22#000000%22%20SIZE%3=
D
> > > %2220%22%3E%3CP%20ALIGN%3D%22CENTER%22%3EChapter%20Title%3C%2FP%3E%3C
> > > %2FFONT%3E
>
> > > and it will convert it to this:
>
> > > <FONT FACE=3D"timesnewroman" COLOR=3D"#000000" SIZE=3D"20"><P
> > > ALIGN=3D"CENTER">Chapter Title</P></FONT>
>
> > > What I am trying to figure out is how to go the other way in perl,
> > > convert the html to an escaped format. Any hints, clues, pointers
> > > would be appreciated
>
> > > Bill H
>
> > Just don't run the input through the unescape sub routine (or have one
> > that does and another that doesn't (and do whatever you want with the
> > other))? =A0Or am I misunderstanding your problem/question?
> > --
> > Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
> > Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
> > and Custom Hosting. =A024/7 support, 30 day guarantee, secure servers.
> > Industry's most experienced staff! -- Web Hosting With Muscle!- Hide qu=
oted text -
>
> > - Show quoted text -
>
> Tim
>
> Actually the problem is that I want to use perl to make a lot of
> default "escaped" html for flash. Up till now I have been just using
> flash to do it, but now I have about 60 templates that I need to
> create and know there has to be a better way then code actionscript,
> run flash, cut / paste escaped stuff into perl code, run perl to
> create template, repeat.
>
> I was thinking of using HTML::Entities, but I can't install it on the
> server I am using.
>
> Bill H- Hide quoted text -
>
> - Show quoted text -

The other thought I had, the brute force approach, is to just escape
every character in the string (ie convert each character to a %??). I
suppose I could get a little creative and not touch any numbers or
letters, just everything below ascii 48, above ascii 57 and below
ascii 65. Above ascii 90 and below ascii 97, and above ascii 122.
Wonder if there is a regex that could do this for me?

Bill H

Posted by Peter J. Holzer on October 18, 2008, 6:01 am
Please log in for more thread options
> The other thought I had, the brute force approach, is to just escape
> every character in the string (ie convert each character to a %??). I
> suppose I could get a little creative and not touch any numbers or
> letters, just everything below ascii 48, above ascii 57 and below
> ascii 65. Above ascii 90 and below ascii 97, and above ascii 122.
> Wonder if there is a regex that could do this for me?

Yes. Search for "character class" in perldoc perlre. Then just translate
what you wrote from English to Regexp.

        hp

Similar ThreadsPosted
CPAN ("first time"): how escape "Enter arithmetic or Perl expression:" loop? June 24, 2005, 4:11 am
escape whitespace in qw/ / November 25, 2004, 8:41 am
How to expand escape sequence (e.g. \n)? September 11, 2004, 4:24 am
regexp with sequences of Escape October 12, 2005, 6:39 pm
printing escape characters November 10, 2005, 1:32 pm
Assignment of var without escape/interpolation April 15, 2006, 12:01 pm
printf + escape code May 22, 2008, 12:36 am
DBD::ODBC,SQL Server,brackets - escape? September 8, 2004, 6:51 pm
How to unambiguously escape non-printables in filenames July 15, 2007, 5:38 am
nested quantifier or unrecognized escape error June 2, 2006, 1:16 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap