Leser: 1
9 Einträge, 1 Seite |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
#!/usr/bin/perl use strict; use warnings; my $text = join '', (<DATA>); my @match = $text =~ /^10.*\r?\n20.*\r?\n01.*$/mg; s/\r?\n/---/g and print for @match; __DATA__ 01|1-123-878|Musterfrau 01|1-010-123|Muster 01|1-051-543|Mayer 20|2-123-452|Bauer 01|2-453-345|Huber 10|1-123-134|Max Mustermann 20|1-456-789|Peter Huber 01|1-457-123|Max Mayer
esskar+2008-06-24 12:32:10--was ist wenn nach der 10 nochmal ne 10 oder ne 11 kommt oder direkt ne 01 kommt?
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
#!/usr/bin/perl use strict; use warnings; my $memory = { lastcode => '', code => '', number => '', name => '' }; while(my $entry = <DATA>) { chomp $entry; my ( $code, $number, $name ) = split /\|/, $entry; if ( $code eq '10' ) { $memory = { %$memory, code => $code, number => $number, name => $name, }; } else { if( $code eq '20' and $memory->{code} eq '10' ) { print join("|", map { $memory->{$_} } qw/code number name/) . " $entry\n" unless cmp_memory( $number, $name); } elsif ( $code eq '01' and $memory->{code} eq '10' && $memory->{lastcode} eq '20' ) { print "$entry\n" unless cmp_memory( $number, $name); } } $memory->{lastcode} = $code; } sub cmp_memory { my ( $number, $name ) = @_; return $number eq ( $memory->{number} || '' ) && $name eq ( $memory->{name} || '' ); } __DATA__ 01|1-123-878|Musterfrau 01|1-010-123|Muster 01|1-051-543|Mayer 20|2-123-452|Bauer 01|2-453-345|Huber 10|1-123-134|Max Mustermann 20|1-456-789|Peter Huber 01|1-457-123|Max Mayer
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
#!/usr/bin/perl # vi:ts=4 sw=4 et: use strict; use warnings; #http://board.perl-community.de/thread/12073/#MSG7 #> global variables #> ---------------------------------------------------------------------------- my $last_num = undef; #> main script #> ---------------------------------------------------------------------------- while ( my $line = <DATA> ) { chomp $line; if ( $line =~ m{^\s*$} ) { print "--8<--\n"; next; } my ( $code, $num, $name ) = split /\|/, $line; if ( defined $last_num ) { if ( $code ne '01' and $num ne $last_num ) { printf "%s|%s|%s\n", $code, $num, $name; } } $last_num = $num; } #> sub routines #> ---------------------------------------------------------------------------- __DATA__ 20|2-114-560|Mayer 01|2-114-560|Mayer 01|2-010-708|Huber 01|2-011-044|Bauer 10|2-147-169|Mayer 20|2-147-554|Bauer 01|2-147-695|Huber 10|2-147-169|Mayer 20|2-147-554|Bauer 30|2-148-554|Muster 01|2-147-695|Huber
9 Einträge, 1 Seite |