1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
use warnings; use strict; my @data = qw( 21112340 21112341 21112342 21112343 21112344 21112345 21112346 21112347 21112348 21112349 21112350 21112351 ); my %sixpack; for my $item (@data) { my $suffix = chop($item); $sixpack{$item}{$suffix}++; } for my $six (sort keys %sixpack) { if (scalar(keys %{$sixpack{$six}}) == 10) { print "$six\n"; } else { print "$six$_\n" for sort keys %{$sixpack{$six}}; } }
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
#!/usr/bin/perl use strict; use warnings; my @array=( 21112340, 21112341, 21112342, 21112343, 21112344, 21112345, 21112346, 21112347, 21112348, 21112349, 21112350, 21112351, ); my %test; for(@array) { $test{$1}+=2**$2 if($_=~/^(\d{7})(\d)/); } my @new_array; for my $val (@array) { my $v=substr($val,0,7); if($test{$v} && $test{$v}==(2**10)-1) { push(@new_array,$v) if(!@new_array or $new_array[-1]!=$v); } else { push(@new_array,$val) } } print "$_\n" for(@new_array);
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
#!/usr/bin/perl use strict; use 5.010; use warnings; my @aa = qw / 21112340 21112341 21112342 21112343 21112344 21112345 21112346 21112347 21112348 21112349 21112350 21112351 /; my (%za, @new); # präfixe zählen, zehner speichern for ( @aa ) { /^\d{7}/; $za{$&}++; push @new, $& if ($za{$&} == 10) } # speichern alles was < 10 ist for ( @aa ) { /^\d{7}/; push @new, $_ if ( $za{$&} < 10 ) } print "$_\n" for( @new ) # noch sortieren
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
#! /usr/bin/perl # vim:ts=4 sw=4 sts=4 et nu fdc=3: use strict; use warnings; use Tie::IxHash; # keep hash sorted; see perldoc Tie::IxHash tie my %part, 'Tie::IxHash'; # read data while ( my $line = <DATA> ) { # split each number into a base (variable length) # and a "postfix" which is the last digit of the number my ( $base, $postfix ) = $line =~ m/(\d+?)(\d)$/; # store the data in an HoA; see perldoc perldsc push @{ $part{$base} }, $postfix; } # create output for my $base ( keys %part ) { my @array = @{ $part{$base} }; # if we have ten postfixes for the base, # just print the base; we do NOT care if # all postfixes are different or not. if ( 10 == @array ) { print $base, $/; } else { print $base.$_.$/ for @array; } } __DATA__ 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 2343 2344 345670 345671 345672 345673 345674 345675 345676 345677 345678 345679 45 46
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
use warnings; use strict; my @data = qw( 21112340 21112341 21112342 21112343 21112344 21112345 21112346 21112347 21112348 21112349 21112350 21112351 512340 512341 512342 512343 512344 512345 512346 512347 512348 512349 512350 512351 ); my %test; my @new; for my $item (@data) { next if $item !~ /^\d{2,}$/; my $suffix = chop($item); $test{$item}{$suffix}++; } for my $base (keys %test) { if (scalar(keys %{$test{$base}}) == 10) { push @new, $base; } else { push @new, $base.$_ for keys %{$test{$base}}; } } print "$_\n" for sort @new;
Guest PhilippAllerdings sollte das Skript mind. 5mal über den Array laufen, sodass auch kürzere Prefixe erkannt werden.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
use warnings; use strict; my @data = qw( # ... ); my @new; my @data_tmp = @data; while (1) { my %test; @new = (); for my $item (@data_tmp) { next if $item !~ /^\d{2,}$/; my $suffix = chop($item); $test{$item}{$suffix}++; } for my $base (keys %test) { if (scalar(keys %{$test{$base}}) == 10) { push @new, $base; } else { push @new, $base.$_ for keys %{$test{$base}}; } } last if $#new == $#data_tmp; @data_tmp = @new; } print "$_\n" for sort @new;
QuoteHallo,
auch, wenn der Thread schon ein bisschen...