Two sum: Difference between revisions
m
→{{header|Perl}}: tweaks to avoid warnings, show revised output
SqrtNegInf (talk | contribs) m (→Functional: tweaks) |
SqrtNegInf (talk | contribs) m (→{{header|Perl}}: tweaks to avoid warnings, show revised output) |
||
Line 1,436:
=={{header|Perl}}==
{{trans|Python}}
<lang perl>use strict;
use warnings;
use feature 'say';
sub two_sum{
my
my $i = 0;
my $j = $#
my @indices;
while ($i < $j) {
if ($
else { $j-- }
}
return @indices
}
my @numbers = <0 2 11 19 90>;
say join ', ', @indices || 'No match';
say join ', ', @indices || 'No match';</lang>
▲my ($n1, $n2) = two_sum(\@numbers, 21);
{{out}}
<pre>1, 3
No match</pre>
=={{header|Perl 6}}==
|