Wie bekomme ich das hin, weil wenn ich an der gesuchten Stelle bin, müsste ich ja $prev Zeilen zurück springen und dann bis $next alles ausgeben.
#!/usr/bin/perlmy $file=$ARGV[0];
my $regexp="Error";
my $num=0;
my $prev=5;
my $next=5;
open(DAT, "< $file") || die("Kann Datei -".$file."- nicht laden!");
while (my $line=<DAT>) {
my $vor="";
my $nach="";
if ($line =~ m/$regexp/) {
$vor=($num-$prev);
$nach=($num+$next);
$count{$regexp}++;
$all+=$count{$regexp};
print "\n\033[1;32m".$regexp."\033[m ";
print "\033[1;31m".$vor."\033[m ";
print "\033[1;33m".$nach."\033[m\n";
for (my $i=$vor; $i<$nach; $i++){
print $num.")\t".$line[$i];
}
$num++;
}
}
close(DAT);