Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code changes when executed

Status
Not open for further replies.

DirectMe

IS-IT--Management
Jul 31, 2002
4
US

I am a newbie to perl and have been trying to adapt some code with contain a subroutine that changes each time I execute it. The character entities are substuted to the html value until the script finally fails. (somewhere about the third execution). I dont know enough perl to see where the problem is. Any assistance will be truely appeciated.

original sub:

sub load_styles
{

my $small = "small";
my $smallxx = "x-small";
if($ENV{HTTP_USER_AGENT} =~ /msie/i and $ENV{HTTP_USER_AGENT} !~ /mac/i){
$small = "x-small";
$smallxx = "xx-small";
}

my $styles = qq^

<script language=&quot;JavaScript&quot;><!--

var pixels_width = window.screen.width;
var pixels_height = window.screen.height;

var nWidth= &quot;640&quot;;
var nHeight=&quot;450&quot;;

if(pixels_width < 740){
nWidth = &quot;540&quot;;
}
if(pixels_height < 540){
nHeight = &quot;350&quot;;
}

var optionString = &quot;titlebar=no,toolbar=no,status=yes,location=no,menubar=yes,resizable=yes,scrollbars=yes,&quot;;
optionString += &quot;height=&quot; + nHeight + &quot;,width=&quot; + nWidth;
optionString += &quot;,screenX=10,screenY=10,top=10,left=10&quot;;

var psWindow = null;

function winOpen(url){
if (!psWindow || psWindow.closed) {
psWindow = window.open(url,&quot;Display&quot;,optionString);
} else {
// window already exists, so bring it forward
psWindow.location.href=url;
psWindow.focus();
}

}

// -->
</script>

<STYLE TYPE=&quot;text/css&quot;>
<!--

BODY {font-family: verdana, arial, helvetica, sans-serif; font-size: $small;}
TR, P, TD, TH, OL, UL, LI { font-family: verdana, arial, helvetica, sans-serif; font-size: $smallxx; }

H1 { font-size: 145%; color: #1E227E; font-family: verdana, arial, helvetica, sans-serif; }
H2 { font-size: 130%; color: #1E227E; font-family: verdana, arial, helvetica, sans-serif; }
H3 { font-size: 115%; font-family: verdana, arial, helvetica, sans-serif; }
H4 { font-size: 100%; color: #36469b; font-family: verdana, arial, helvetica, sans-serif; }
H5 { font-size: 85%; font-family: verdana, arial, helvetica, sans-serif; }
H6 { font-size: 70%; font-family: verdana, arial, helvetica, sans-serif; }
PRE, TT, CODE { font-family: courier, sans-serif; font-size: $smallxx; }
A { color: #000099; font-size: $smallxx; }
A:visited { color: #000099; font-size: $smallxx; }
A:active {color:#333366;}
A:link {color:#000099; font-size: $smallxx; }
A:hover { font-weight: normal color: #930;}

-->
</STYLE>
^;
return $styles;
}


After execution:

the quotes change to their character entities amp quot.
Then in the next execution the ampersands are substituted with their entities and so on until the script fails.
 
I've tried pasting the function into a little CGI script and get the same result every time, with no HTML entity encoding. I can only assume you have a call to something like encode_entities within the HTML::Entities module, either on this specific string, or another string that this one has been added to.

Perl won't automatically convert characters to their HTML entities, so the code you are using must be making a call to convert them.
Barbie
Leader of Birmingham Perl Mongers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top