#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    14
    Rep Power
    0

    What is wrong with this code?


    Can you tell me why this code is not correct.

    Code:
    $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;",-onmouseover=>"this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';"\<center\>\<script language=javascript\>\n"document.write(mystats[".$imagedetails[0]."]);"\n\</script\>\<br\>";\<img src=\'/cgi-bin/snapad.cgi?x=".($startx+$arealeft)."&amp;y=".$starty."&amp;width=".$width."&amp;height=".$height."&amp;image=1\'\>\</center\>');window.status='$imagedetails[1]';shw('$imagedetails[0]-pop',event);return true;",-onmouseout=>"window.status=' ';shw('$imagedetails[0]-pop',event);return true;"},'')."\n";
  2. #2
  3. Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Feb 2004
    Posts
    512
    Rep Power
    50
    You have to tell what you want it to do / what you expect the results to be and if it is erroring, what the error is or what your problem symptom is.

    Otherwise your asking, "Why is my apple green"?

    Comments on this post

    • Axweildr agrees
    • dsb agrees
  4. #3
  5. Contributing User
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2003
    Location
    in da kitchen ...
    Posts
    12,871
    Rep Power
    6466
    Ask better questions, get better answers, check out the FAQ's

    I'd start by breaking into smaller variables, rather than having a go at that monster
    --Ax
    without exception, there is no rule ...
    Handmade Irish Jewellery
    Targeted Advertising Cookie Optout (TACO) extension for Firefox
    The great thing about Object Oriented code is that it can make small, simple problems look like large, complex ones


    09 F9 11 02
    9D 74 E3 5B
    D8 41 56 C5
    63 56 88 C0
    Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
    -- Jamie Zawinski
    Detavil - the devil is in the detail, allegedly, and I use the term advisedly, allegedly ... oh, no, wait I did ...
    BIT COINS ANYONE
  6. #4
  7. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,274
    Rep Power
    0
    Dropping your line into a script results in this error with strict and warnings on:
    Code:
    Backslash found where operator expected at ./dv line 18, near ""this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';"\"
            (Missing operator before \?)
    syntax error at ./dv line 18, near ""this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';"\"
    Excessively long <> operator at ./dv line 18.
    But I could see the error in my editor even before running. The line isn't terminated properly, because you didn't escape the double quotes.

    This will run at least, but I don't know if it gives the result you hope for:
    Code:
    my $q = CGI->new();
    my $div = $q->div(
    	{
    		-style=>qq|position:absolute;left:".($startx+$arealeft)."px;top:".($starty+$areatop)."px;width:".$width."px;height:".$height."px;cursor:pointer;|,
    		-onclick=>qq|Start('$cgiurl?id=$custid');return true;|,
    		-onmouseover=>qq|this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';"\<center\>\<script language=javascript\>\n"document.write(mystats[".$imagedetails[0]."]);"\n\</script\>\<br\>";\<img src=\'/cgi-bin/snapad.cgi?x=".($startx+$arealeft)."&amp;y=".$starty."&amp;width=".$width."&amp;height=".$height."&amp;image=1\'\>\</center\>');window.status='$imagedetails[1]';shw('$imagedetails[0]-pop',event);return true;|,
    		-onmouseout=>qq|window.status=' ';shw('$imagedetails[0]-pop',event);return true;|
    	},' ');
    
    my $newdiv='<!-- ADD DIVS -->'."\n".$div."\n";
    But this is the point where you should be thinking, 'Hey! I gotta get this javascript out of my perl script so it will be more readable.

    Since you are inserting perl variables into the javascript, I'd recommend HTML template. You can code the HTML and javascript in a separate file, and fill in the placeholders from your perl code.

    Comments on this post

    • ishnid agrees
    Last edited by keath; January 4th, 2006 at 09:56 AM.
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2005
    Posts
    14
    Rep Power
    0

    Result and require


    Thanks Keath for your most appreciated reply.

    Can you tell me what editor you are using. It would be helpful to run my code in first. Then I wouldn't be pestering you guys so often.

    After adding your updated code, I was returned with the following result. It is close to what I want but not quite.

    Here is what was returned on the html page:

    Code:
    <div style="position:absolute;left:&quot;.(480+0).&quot;px;top:&quot;.(110+70).&quot;px;width:&quot;.20.&quot;px;height:&quot;.20.&quot;px;cursor:pointer;" onmouseout="window.status=' ';shw('21-pop',event);return true;" onclick="Start('http://www.milliondollarhomepageaustralia.net/cgi-bin/stats.cgi?id=21');return true;" onmouseover="this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';&quot;&lt;center&gt;&lt;script language=javascript&gt;
    &quot;document.write(mystats[&quot;.21.&quot;]);&quot;
    &lt;/script&gt;&lt;br&gt;&quot;;&lt;img src='/cgi-bin/snapad.cgi?x=&quot;.(480+0).&quot;&amp;amp;y=&quot;.110.&quot;&amp;amp;width=&quot;.20.&quot;&amp;amp;height=&quot;.20.&quot;&amp;amp;image=1'&gt;&lt;/center&gt;');window.status='http://www.testing.com';shw('21-pop',event);return true;"> </div>
    What I need returned is:


    Code:
    <div onclick="Start('http://www.milliondollarhomepageaustralia.net/cgi-bin/stats.cgi?id=8');return true;" onmouseout="window.status=' ';shw('8-pop',event);return true;" onmouseover="this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape('<center><script language=javascript>document.write(mystats[8]);</script><br>\<img src=\'/cgi-bin/snapad.cgi?x=790&amp;y=70&amp;width=80&amp;height=10&amp;image=1\'\></center>');window.status='http://www.chrismunce.com.au';shw('8-pop',event);return true;" style="position:absolute;left:790px;top:140px;width:80px;height:10px;cursor:pointer;">
    </div>
    I really appreciate your help.

    Kind Regards & Thanks




    Originally Posted by keath
    Dropping your line into a script results in this error with strict and warnings on:
    Code:
    Backslash found where operator expected at ./dv line 18, near ""this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';"\"
            (Missing operator before \?)
    syntax error at ./dv line 18, near ""this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';"\"
    Excessively long <> operator at ./dv line 18.
    But I could see the error in my editor even before running. The line isn't terminated properly, because you didn't escape the double quotes.

    This will run at least, but I don't know if it gives the result you hope for:
    Code:
    my $q = CGI->new();
    my $div = $q->div(
    	{
    		-style=>qq|position:absolute;left:".($startx+$arealeft)."px;top:".($starty+$areatop)."px;width:".$width."px;height:".$height."px;cursor:pointer;|,
    		-onclick=>qq|Start('$cgiurl?id=$custid');return true;|,
    		-onmouseover=>qq|this.T_WIDTH=170;this.T_BGCOLOR='#ffffff';return escape(';"\<center\>\<script language=javascript\>\n"document.write(mystats[".$imagedetails[0]."]);"\n\</script\>\<br\>";\<img src=\'/cgi-bin/snapad.cgi?x=".($startx+$arealeft)."&amp;y=".$starty."&amp;width=".$width."&amp;height=".$height."&amp;image=1\'\>\</center\>');window.status='$imagedetails[1]';shw('$imagedetails[0]-pop',event);return true;|,
    		-onmouseout=>qq|window.status=' ';shw('$imagedetails[0]-pop',event);return true;|
    	},' ');
    
    my $newdiv='<!-- ADD DIVS -->'."\n".$div."\n";
    But this is the point where you should be thinking, 'Hey! I gotta get this javascript out of my perl script so it will be more readable.

    Since you are inserting perl variables into the javascript, I'd recommend HTML template. You can code the HTML and javascript in a separate file, and fill in the placeholders from your perl code.
  10. #6
  11. kill 9, $$;
    Devshed Supreme Being (6500+ posts)

    Join Date
    Sep 2001
    Location
    Shanghai, An tSín
    Posts
    6,878
    Rep Power
    3891
    You need to turn off autoescaping for the HTML for your CGI object. Insert the following into keath's code:
    Code:
    my $q = CGI->new();
    
    $q->autoEscape(0);
    
    my $div = $q->div(
    # etcetera

    Comments on this post

    • keath agrees : Thanks. Much better. (no points left, sorry)
    • icrf agrees : proxy++
  12. #7
  13. !~ /m$/
    Devshed Specialist (4000 - 4499 posts)

    Join Date
    May 2004
    Location
    Reno, NV
    Posts
    4,274
    Rep Power
    0
    Regarding editors:

    I use BBedit on Mac OS X. The syntax highlighting for perl is excellent, and catches even complex cases. It's expensive. Really kind of remarkably expensive. I use it so much that I feel the cost was justified for me, but they also offer a less feature packed editor called TextWrangler for free. I'd recommend anyone programming on OS X try it at least.

    Good syntax highlighting is a really useful thing. Can easily catch string termination errors.

    Cue everyone to recommend your favorite editor again.
  14. #8
  15. 8 Miles
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2005
    Location
    India
    Posts
    356
    Rep Power
    78

    reg. Editors


    hi ,

    I'm using Komodo Editor on Windows box. This also reports syntax errors, hightlighting. Free to download and evaluate.
    EditPlus is also good...

    Does anybody throw some light on Eclispse.. its for java but will it be used for Perl also..

    Kalyan
  16. #9
  17. Perl Monkey
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    May 2003
    Location
    the far end of town where the Grickle-grass grows
    Posts
    1,860
    Rep Power
    113
    I made a big list of editors over on TT awhile back: http://tek-tips.com/faqs.cfm?fid=5835

    Comments on this post

    • Axweildr agrees : Welcome back Andrew
    Andrew - Perl (and VB.NET) Monkey

    Never underestimate the bandwidth of a hatchback full of tapes.

IMN logo majestic logo threadwatch logo seochat tools logo