Fundamentals of SVG Programming: Concepts to Source Code (Graphics Series)
|
|
|
Generating a Simple SVG Document with Perl
Consider the red rectangle displayed in Figure 17.1.
The Perl script
Listing 17.1 simplePerl1.pl
print "<svg>\n"; print " <g transform=\"translate(50,50)\">\n"; print " <rect x=\"0\" y=\"50\" width=\"20\" height=\"50\"\n"; print " style=\"fill:red\"/>\n"; print " </g>\n"; print "</svg>\n";
The SVG document script in Listing 17.2 is the output of the Perl script in Listing 17.1.
Listing 17.2 simplePerl1.svg
<svg> <g transform="translate(50,50)"> <rect x="0" y="50" width="20" height="50" /> </g> </svg>
Remarks
After you have added the directory containing the Perl executable to your PATH variable, you can generate the SVG document displayed in Listing 17.2 by invoking Perl from the command line as follows:
perl -w simplePerl1.pl >simplePerl1.svg
The Perl script in Listing 17.2 contains of a set of print statements that print each line of SVG code. While this is acceptable for very small SVG documents, this technique becomes cumbersome with SVG documents that are more than a page in length. A slightly better approach is demonstrated in the next example.
|
|
|