#!/usr/bin/env perl

use 5.022;
use strict;
use warnings;

$| = 1;

my @bunch = ();
while (<<>>) {
    s/^\s+//;
    my @e = split /\s+/;
    next if !@e;

    die "integer numbers separated by whitespace expected\n"
        if grep { !/^(?:0|[1-9][0-9]*)\z/ } @e;

    push @bunch, \@e;
}

my @sorted =
    sort {
        my $cmp = @{$a} <=> @{$b};
        my $i = 0;
        while (!$cmp && $i < @{$a}) {
            $cmp = $a->[$i] <=> $b->[$i];
            ++$i;
        }
        $cmp
    } @bunch;

foreach my $r (@sorted) {
    print "@{$r}\n";
}

__END__
=head1 NAME

numlist_sort - sort a list of a list of numbers

=head1 SYNOPSIS

  numlist_sort [file]...

=head1 DESCRIPTION

This example program reads lines with lists of non-negative integer
numbers, separated by whitespace, sorts the list of lists, first by
size, then by first element, then by second element, etc., and writes
the final result to standard output.

=head1 AUTHOR

Martin Becker, E<lt>becker-cpan-mp I<at> cozap.comE<gt>

=head1 COPYRIGHT AND LICENSE

Copyright (c) 2019 by Martin Becker, Blaubeuren.  All rights reserved.

This library is free software; you can redistribute it and/or modify
it under the same terms as Perl itself, either Perl version 5.10.0 or,
at your option, any later version of Perl 5 you may have available.

=head1 DISCLAIMER OF WARRANTY

This library is distributed in the hope that it will be useful, but
without any warranty; without even the implied warranty of merchantability
or fitness for a particular purpose.

=cut
