[Vienna-pm] Trennzeile - das ewig muehsame

Wolfgang Laun Wolfgang.Laun at alcatel.at
Tue Sep 5 23:19:31 PDT 2006


Noch eine Variante:

sub getSepBuilder {
    my $currSep =
    my $primSep = "";
    my $succSep = shift;
    return sub { $currSep = $primSep; $primSep = $succSep; $currSep; }
}

my $getSep = getSepBuilder( ( '-' x 80 ) . "\n" );

foreach (@out){
    print $getSep->() if /Anfang/;
    print;
}

mfg
Wolfgang

Baier Oliver wrote:

>Hi,
>
>ich habe eine Liste, die mehrere zusammenhaengende Bloecke beinhaltet
>und will zwischen jedem Block eine Trennzeile ausgeben; allerdings
>nicht in der allerersten Zeile. Da das End-Pattern variabel ist, bin
>ich vom Anfangspattern abhaengig und auf Anhieb sind mir mal folgende
>haessliche Ansaetze eingefallen:
>
>A)	my $row = 0;
>	foreach (sort @out) {
>		print "-" x 80 ,"\n" if /Anfangspattern/ && $row++ != 0;
>		print;
>	}
>
>	Nachteil: Counter mitschleppen
>
>B)	foreach (sort @out) {
>		print "-" x 80 ,"\n" if /Anfangspattern/ && $_ !~
>$out[0];
>		print;
>	}
>
>	Nachteil: wiederholtes Pattern matching
>
>C)	my @sorted = sort @out;
>	foreach my $i (0 .. $#sorted) {
>		print "-" x 80 ,"\n" if $sorted[$i] =~ /Anfangspattern/
>&& $i != 0;
>		print $sorted[$i];
>	}
>
>	Nachteil: extra sortierte Liste
>
>
>Eigentlich suche ich ein:
>
>	foreach (sort @out) {
>		print "-" x 80 ,"\n" if /Anfangspattern/ && $_
><nicht_erstes_Element>;
>		print;
>	}
>
>aber das gibt es ja glaub ich nicht auf diese Weise.
>Wie loest ihr diese Trennzeilenprobleme immer?
>
>lg
>Oliver
>_______________________________________________
>Vienna-pm mailing list
>Vienna-pm at pm.org
>http://mail.pm.org/mailman/listinfo/vienna-pm
>  
>



More information about the Vienna-pm mailing list