fork download
  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5. use v5.24;
  6.  
  7. my @Arr = ('1.1', '2.4.5', '1.1.1', '3.4');
  8. my %Tmp = ();
  9.  
  10. foreach my $i (@Arr) {
  11. $Tmp{$i} = '*';
  12. my $j = $i;
  13. while ($j =~ /^(.+).\d/) {
  14. $j = $1;
  15. $Tmp{$j} = '*';
  16. }
  17. }
  18.  
  19. my @Res = sort {return (length($a) == length($b)) ? $a cmp $b : length($b) <=> length($a)} keys %Tmp;
  20. map {say $_ } @Res;
Success #stdin #stdout 0.01s 5416KB
stdin
Standard input is empty
stdout
1.1.1
2.4.5
1.1
2.4
3.4
1
2
3