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

    Join Date
    Jun 2001
    Rep Power

    Question Parsing Dreamweaver-JavaScript through a perl script - buggy?


    i'm using a simple script what reads a html-template and parses it to the browser.

    I do have a test-template like this:

    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    function MM_swapImgRestore() { //v3.0
      var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
    function MM_preloadImages() { //v3.0
      var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
        var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
        if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
    function MM_findObj(n, d) { //v4.01
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && d.getElementById) x=d.getElementById(n); return x;
    function MM_swapImage() { //v3.0
      var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
       if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
    <body bgcolor="#FFFFFF" text="#000000" onLoad="MM_preloadImages('b_o_home_01-over.gif')">
    <p><a href="#" onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','b_o_home_01-over.gif',1)"><img name="Image1" border="0" src="b_o_home_01.gif" width="120" height="15"></a></p>
    My perlscript uses the following routines:

    sub ReadTemplate {
        my $msg  =  shift @_;
        my $file =  shift @_;
        $file    =~ s#\.\./##g;
        $file    =~ s/[^\w-\.]//g;
        $file    = $basepath . $file;
        open(FILE, "$template") or Error('$!");
        my @lines = (<FILE>);
        close(FILE)or Error($!");
        return @lines;
    sub ParseText {
        my ($line, $key, $value, $sub);
        foreach $line (@_)
            while (($key => $value) = each %FORM)
                { $line =~ s/\[$key\]/$value/ig }
            while (($key => $value) = each %ENV)
                { $line =~ s/\[\%$key\]/$value/ig }
            $line =~ s/\[[^<](.)*?[^>]\]//g;
        foreach $line (@_)
            while ($line =~ /\[<((.)*?)>\]/)
                $sub = $1;
                $sub =~ s/[^\d\+\*\/\-%\.x<>\(\)]//g;
                $sub = eval $sub;
                $sub = sprintf ("%.2f", $sub); 
                $line =~ s/\[<(.)*?>\]/$sub/
        return @_;
    sub Output { 
         print "$content_type@_\n" 
    If i parse this template through my script i'll get errors on moving the mouse over the image ...

    Any idea how i could change this so that those damned Dreamweaver-Code is displayed correctly?

    Thanks for your help.
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2001
    North Vancouver, BC, Canada
    Rep Power


    Try putting the script in an external file.

    at the top of the web page put :

    <script language="javascript" src="YourScript.js"></script>

    That way perl will not look into the file and change any code.

    Hope this helps.

    Foot in Mouth ver 1.2.5 Onion

IMN logo majestic logo threadwatch logo seochat tools logo