Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Line using Perl

The code:

use strict;
use warnings;
use SVG (-nocredits => 1, -inline => 1);

my $svg= SVG->new( width => 200, height => 200);
$svg->line(
    x1 =>  0,
    y1 =>  0,
    x2 => 200,
    y2 =>  200,
    style => "stroke:blue;stroke-width:5",
);

$svg->line(
    x1 =>  0,
    y1 =>  200,
    x2 => 200,
    y2 =>  0,
    stroke => "red",
    "stroke-width" => 5,
);

# green horizontal line
$svg->line(
    x1 =>  0,
    y1 =>  50,
    x2 =>  200,
    y2 =>  50,
    stroke => "#0F0",
    "stroke-width" => 5,
);


# vertical line
$svg->line(
    x1 =>  50,
    y1 =>  0,
    x2 =>  50,
    y2 =>  200,
    stroke => "rgb(86, 126, 169)",
    "stroke-width" => 5,
);


print $svg->xmlify();

The generated SVG

<svg height="200" width="200" xmlns="http://www.w3.org/2000/svg" xmlns:svg="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
	<line style="stroke:blue;stroke-width:5" x1="0" x2="200" y1="0" y2="200" />
	<line stroke="red" stroke-width="5" x1="0" x2="200" y1="200" y2="0" />
	<line stroke="#0F0" stroke-width="5" x1="0" x2="200" y1="50" y2="50" />
	<line stroke="rgb(86, 126, 169)" stroke-width="5" x1="50" x2="50" y1="0" y2="200" />
</svg>

The image:

Line