perl 5.12.1
Version of implementation Perl of programming language PerlA version of perl compiler.
Examples:
Quadratic equation - Perl (233):
Note that Perl 6 has no backwards compatibility; this example won’t be valid in Perl 6.
$A = <>;
if ($A == 0) {
print "Not a quadratic equation.";
}
else {
$B = <>;
$C = <>;
$D = $B * $B - 4 * $A * $C;
if ($D == 0) {
print "x = ", -0.5 * $B / $A;
}
else {
if ($D > 0) {
print "x1 = ", 0.5*(-$B + sqrt($D))/$A, "\nx2 = ", 0.5*(-$B - sqrt($D))/$A
}
else {
print "x1 = (", -0.5*$B/$A, ",", 0.5*sqrt(-$D)/$A, ")\nx2 = (", -0.5*$B/$A, ",", -0.5*sqrt(-$D)/$A, ")\n"
}
}
}
CamelCase - Perl (365):
my $text = <STDIN>;
$text = join('', map(ucfirst, split(/[^a-z]+/, lc $text)));
print $text, "\n";
CamelCase - Perl (371):
This is similar to the previous example, except that instead of splitting on non-alphabetical characters, we match on runs of alphabetical characters.
my $text = <STDIN>;
$text = join('', map(ucfirst, lc($text) =~ /[a-z]+/g));
print "$text\n";
Comments
]]>blog comments powered by Disqus
]]>