in reply to Re: Refactoring Redux...
in thread Refactoring Redux...

Unquoted heredoc terminators in the << are not nice. And you can add another step:
my $y = 0; my @list; foreach (@scores) { if ($_ != 0) { push(@list, $y++, @list, $_ * -1.0); } } my $list = join(",",@list); print << "SVG"; <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg height="200" width="200"> <line x1="0" y1="0" x2="80" y2="0"/> <polyline points="$list" style="stroke: black; width: 1px; fill: non +e;"/> </svg> SVG
And now we're moving in the right direction - separate the application logic from the output logic. Let's go another step towards it:
my $y = 0; my @list; foreach (@scores) { if ($_ != 0) { push(@list, $y++, @list, $_ * -1.0); } } print << "SVG"; <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN" "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd"> <svg height="200" width="200"> <line x1="0" y1="0" x2="80" y2="0"/> <polyline points="@{[ join(",", @list) ]}" style="stroke: black; width: 1px; fill: none;"/> </svg> SVG
Finally we wrap up by collapsing the application logic:
my @list = map { $scores[$_] != 0 ? ($_, $scores[$_] * -1.0) : () } 0 .. $#scores;

No extra temporary variables, no scattered output, application logic minimized. The next step, assuming this is part of a larger app, would be Template Toolkit.

Actually, thinking about it, it's debatable whether the != 0 distinction is part of the application logic or part of the display logic. One might just as well do

my @l_list = map [ $_, $scores[$_] * -1.0 ], 0 .. $#scores; print << "SVG"; ... @{[ join ",", map @$_, grep $_->[0] != 0, @l_list; ]} ...

Which leads me to question my term "application logic" - one might just as well consider the pairing of data points and coordinates display logic and shift it all into the template. That depends on the specific situation at hand.

At any rate, this is a very important distinction to make, and to make consciously. I see failure to do so all the time even though it's just as important everywhere else as in web related programming. Maintainability and clarity is best achieved if you do exactly one cleanly defined thing at a time in every piece of your code. Be careful not to mix up activities. Of course the entire concept hinges on the idea of clean data structure design and in a way, that means clean interfaces between parts of your code. All of these matters are interrelated, and mastering them is what makes one a great software engineer.

Makeshifts last the longest.