Why do you need to simplify the code? Reducing the number of lines is not easy, but refactoring the similar parts to subroutines is possible:
sub assign_max {
my ($x, $y) = @_;
$s[$b1] = max($x, $y);
}
sub compare {
my ($ar, $idx, $subst) = @_;
if ($ar->[$idx] == 0 && $subst > 0) {
$ar->[$idx] = $subst;
}
}
$h = $s[$b] == 0 ? 0 : $s[$b] - 1 unless $l == $k;
$c = (0, 1, 2)[$l <=> $k];
if ($l < $k) {
compare(\@s_rev, $d + 1, $k - 2);
assign_max($k, $lt);
$j++;
} elsif ($l > $k) {
compare(\@s, $b + 1, $l - 2);
assign_max($l, $kt);
$i++;
} else {
compare(\@s, $b + 1, $k - 2);
assign_max($k, $lt);
$h = 0;
}
As you can see,
assign_max uses @s and $b1 as globals.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.