#!/usr/bin/perl

#-w
$^W=1;

my @ips;
my $my_exitvalue;

@ips=();
$my_exitvalue=0; #track error(s)

while (<>){
	chomp;
	#match to IPv4 dotted quad address?
	if(
		!
		/^
			(
				(
					\d\d?|		#a digit or two
					[01]\d\d|2[0-4]\d|25[0-5]	#or three (in range)
				)
				\. #dot
			){3} #thrice that
			(
				\d\d?|		#a digit or two
				[01]\d\d|2[0-4]\d|25[0-5]	#or three (in range)
			)
		$/ox
	){
			#input didn't match, write to stderr, track, and skip to next
			warn "$0: input ($_) doesn't match expected ipv4 dotted quad format\n";
			$my_exitvalue=1; #track error(s)
			next;
	};
	#it matched, "normalize" it (strip extraneous leading zeros)
	s/(^|\.)0+(\d)/\1\2/go;
	#print "$_\n";
	push @ips, ($_);
}

print (
	join("\n",
		sort
			{
				my @aaaa=split /\./, $a;
				my @bbbb=split /\./, $b;
				$aaaa[0] <=> $bbbb[0] ||
				$aaaa[1] <=> $bbbb[1] ||
				$aaaa[2] <=> $bbbb[2] ||
				$aaaa[3] <=> $bbbb[3]
			} @ips
	)
);

#join() covered separators, but we also typically need terminator:
if(@ips){print "\n";};

#@mount=sort {
#		if(@$a[1] eq $pri && @$b[1] ne $pri) { return -1; }
#		if(@$b[1] eq $pri && @$a[1] ne $pri) { return 1; }
#	}
#	@$a cmp @$b;
#}	@mount;
#
#foreach $line (@mount) {
#	print join("\0",(@{$line}[0..2]),join(',',@{${$line}[3]})),"\n";
#}
