in reply to Escaping special characters for HTML
or similar notation where the double quotes are for Perl and not part of the data - and save the normal " double quotes for where they *need* to be used in the HTML/JavaScript/CSS.. qq~key="value"~
It will make it much easier to tell where the quotes need to be, and you will be able to have double quotes in your data without escaping them.
You are also using more concatination operators than you need to (which doesn't make your code any faster!)
e.g. where you have:
You could use:."px;width:".$width."px;height:".$height."px;cursor:pointer;"
i.e. protecting the scalar names with {} where they have to be followed immediately by more plain text or underscores.. "px;width:${width}px;height:${height}px;cursor:pointer;"
This will improve readability because it will make the code look more like the output is going to look and make the Perl scalars stand out a bit within the code.
NB: you don't *need* to do this when the scalar is followed by an ampersand or other non-variable name character (beware of [ or { which would be the start of an array index or hash though!)
It could also simplify things if you did your maths before the assignment instead of embedding it into the concatination if you don't need it to change while it's in the concatination (especially as you're doing the same maths more than once):
could become:$newdiv='<!-- ADD DIVS -->'."\n".div({-style=>"position:absolute;left: +".($startx+$arealeft)."px;top:".($starty+$areatop)."px;width:".$width +."px;height:".$height."px;cursor:pointer;",-onclick=>"Start('$cgiurl? +id=$custid');return true;",
the only bit that looks particularly broken is the -onmouseover => '...' - it has two 'return's in it for starters... and I'm not sure what else wrong with it, but apart from that I get:my $tmp_left = $startx + $arealeft; my $tmp_top = $starty + $areatop; $newdiv= "<!-- ADD DIVS -->\n" . div( { -style => "position:absolute;left:${tmp_left}px;top:${tmp_top} +px;width:${width}px;height:${height}px;cursor:pointer;", -onclick => "Start('$cgiurl?id=$custid');return true;", ...
my $tmp_left = $startx + $arealeft; my $tmp_top = $starty + $areatop; my $newdiv= "<!-- ADD DIVS -->\n" . div( { -style => "position:absolute;left:${tmp_left}px;top:${tmp_ +top}px;width:${width}px;height:${height}px;cursor:pointer;", -onmouseover => ( fix this bit... ), -onclick => "Start('$cgiurl?id=$custid');return true;", -onmouseout => "window.status=' ';shw('$imagedetails[0]-po +p',event);return true;", }, '' ) ."\n";
|
---|