Where you are needing to nest double quotes I would recommend using
. qq~key="value"~
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.

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:

."px;width:".$width."px;height:".$height."px;cursor:pointer;"
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.

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):

$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;",
could become:
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;", ...
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; 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";

In reply to Re: Escaping special characters for HTML by serf
in thread Escaping special characters for HTML by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.