Baz has asked for the wisdom of the Perl Monks concerning the following question:

I have a SVG doc in the order of 100Ks. This doc contains a map divided into about 100 sectors, and I shade each of these sectors to represent a certain statistic. To do this shading I decided to create a javascript array - as I could then use some javascript to set the colors at run time instead of hard coding all the colors using the styling tags. The reason I did this was because I thought it would be easier from a perl perspective. Now when I wish to present a statistic to the client, I can open up my server side generic svg doc, fill in the array with the desired colors, and spit the result to the client. Does that sound daft?
Anyway I've placed this empty array (colors1) near the start of my svg doc - looking something like this -
<?xml version="1.0" standalone="no" ?> <!-- Created by "Barry Griffin" --> <!-- (C) Barry Griffin 2002 --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg id="mainmap" xml:space="preserve" style="shape-rendering:geometri +cPrecision; text-rendering:geometricPrecision; image-rendering:optimizeQuality" onload="init(evt)" width="800" height="420"> <script type="text/ecmascript"> <![CDATA[ var colors1 = []; REST OF DOC...
So how should I go about filling this array using perl, and then send it to the client? Sorry for not presenting any perl - I have the color values stored in a @colorArray, after that I'm not sure how to tackle the problem, thanks.

Replies are listed 'Best First'.
Re: Parsing a 100K doc
by dws (Chancellor) on Aug 23, 2002 at 19:04 UTC
    Now when I wish to present a statistic to the client, I can open up my server side generic svg doc, fill in the array with the desired colors, and spit the result to the client. Does that sound daft?

    No. It sounds like you're using a very big template.

    So how should I go about filling this array using perl, and then send it to the client?

    Look into one of the available templating mechanisms. Text::Template might do what you want.

    Also, merlyn has an article onTemplate-Driven File Management that describes some non-obvious ways to use templates.

Re: Parsing a 100K doc
by fglock (Vicar) on Aug 23, 2002 at 19:05 UTC

    I'd use a bitmap instead (JPG). I think the point of using SVG is for vector graphics.

    Anyway, take a look ate the "html" output format of the Gimp. It is very interesting and might give you some ideas (I think there is a perl interface to the Gimp too).

      Thanks Guys, I'll look into your suggestions

      I have a png version at the moment - PNG
      and a svg version - SVG

      The reason I think I'm going to prefer SVG is in respect to image mapping - as I need to display the towns for each sector.
Re: Parsing a 100K doc
by BrowserUk (Patriarch) on Aug 24, 2002 at 04:43 UTC

    One way..

    #! perl -w use strict; my @colors = ( [167,45,37,56,65,67,56,78,231,35,142,20,187,137,19,107 +,117,127,137], # ... [221,245,237,0,0,0,0,0,235,235,145,220,218,146,194,46,133, +127,45,32] # ... ); # open DATA, '<g3.svg.tmpl' or die $!; #open OUT, '>g3.svg' or die $!; local $" = ','; # localise $" ($LIST_SEPAR +ATOR) and set it to be a comma # interpolate the arrays into matching lines s/^var colors(\d+) = \[\];/var colors$1 = "[@{ $colors[$1 - 1] }]";/ + and print # OUT # and print +it if it matched or print #OUT # otherwise ju +st print them while <DATA>; #close DATA or warn $!' #close OUT or warn $!' =pod Output C:\test>192405 <?xml version="1.0" standalone="no" ?> <!-- Created by "Barry Griffin" --> <!-- (C) Barry Griffin 2002 --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg id="mainmap" xml:space="preserve" style="shape-rendering:geometri +cPrecision; text- rendering:geometricPrecision; image-rendering:optimizeQuality" onload="init(evt)" width="800" height="420"> <script type="text/ecmascript"> <![CDATA[ var colors1 = "[167,45,37,56,65,67,56,78,231,35,142,20,187,137,19,107, +117,127,137]"; var colors2 = "[221,245,237,0,0,0,0,0,235,235,145,220,218,146,194,46,1 +33,127,45,32]"; REST OF DOC... C:\test> =cut __DATA__ <?xml version="1.0" standalone="no" ?> <!-- Created by "Barry Griffin" --> <!-- (C) Barry Griffin 2002 --> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 20010904//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg id="mainmap" xml:space="preserve" style="shape-rendering:geometri +cPrecision; text- rendering:geometricPrecision; image-rendering:optimizeQuality" onload="init(evt)" width="800" height="420"> <script type="text/ecmascript"> <![CDATA[ var colors1 = []; var colors2 = []; REST OF DOC...