RosettaCodeData/Task/Order-two-numerical-lists/Perl/order-two-numerical-lists.pl

39 lines
855 B
Perl
Raw Permalink Normal View History

2016-12-05 22:15:40 +01:00
use strict;
use warnings;
2013-04-10 23:57:08 -07:00
sub orderlists {
2016-12-05 22:15:40 +01:00
my ($firstlist, $secondlist) = @_;
my ($first, $second);
while (@{$firstlist}) {
$first = shift @{$firstlist};
if (@{$secondlist}) {
$second = shift @{$secondlist};
if ($first < $second) {
return 1;
}
if ($first > $second) {
return 0;
}
}
else {
return 0;
}
}
2013-04-10 23:57:08 -07:00
2016-12-05 22:15:40 +01:00
@{$secondlist} ? 1 : 0;
2013-04-10 23:57:08 -07:00
}
2016-12-05 22:15:40 +01:00
foreach my $pair (
[[1, 2, 4], [1, 2, 4]],
[[1, 2, 4], [1, 2, ]],
[[1, 2, ], [1, 2, 4]],
[[55,53,1], [55,62,83]],
[[20,40,51],[20,17,78,34]],
) {
my $first = $pair->[0];
my $second = $pair->[1];
my $before = orderlists([@$first], [@$second]) ? 'true' : 'false';
print "(@$first) comes before (@$second) : $before\n";
2013-04-10 23:57:08 -07:00
}