1 2 3 4 5 6 7 8 9 10
$reg1 = 1; $reg2 = 0; ... open my $dat, "< Datei" or die "Geht nicht :(\n"; while (<$dat>){ if (($reg1) && (/^unleserliches\s+Konstrukt/)){...} if (($reg2) && (/xyz/)){...} ... }
2011-05-10T13:13:08 Sven_123drei von den vier Benutzern, die neben mir on sind, dabei sind, ihn zu lesen...*g)
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 use strict; use warnings; use Benchmark; timethese(100000 => { normal => sub { open my $in, "< molpro.out" or die "geht nicht\n"; my ($r1,$r2,$r3) = (1,1,0); while (<$in>){ if (($r1) && (/^\s*?!MCSCF STATE (\d+).1 ENERGY/)){my $x = $1} if (($r2) && (/^\s*?SA-MC GRADIENT FOR STATE (\d+).1/)){my $x = $1} if (($r3) && (/^\s*?SA-MC NACME FOR STATES (\d+).1 - (\d+).1/)){my $x = $1} } }, mit_qr => sub { open my $in, "< molpro.out" or die "geht nicht\n"; my ($r1,$r2,$r3) = (1,1,0); my $re1 = qr/^\s*?!MCSCF STATE (\d+).1 ENERGY/; my $re2 = qr/^\s*?SA-MC GRADIENT FOR STATE (\d+).1/; my $re3 = qr/^\s*?SA-MC NACME FOR STATES (\d+).1 - (\d+).1/; while (<$in>){ if (($r1) && (/$re1/)){my $x = $1} if (($r2) && (/$re2/)){my $x = $1} if (($r3) && (/$re3/)){my $x = $1} } }, extra => sub { my ($r1,$r2,$r3) = (1,1,0); my $re1 = qr/^\s*?!MCSCF STATE (\d+).1 ENERGY/; my $re2 = qr/^\s*?SA-MC GRADIENT FOR STATE (\d+).1/; my $re3 = qr/^\s*?SA-MC NACME FOR STATES (\d+).1 - (\d+).1/; if ($r1){ open my $in, "< molpro.out" or die "geht nicht\n"; while (<$in>){ if (/$re1/){my $x = $1} } } if ($r2){ open my $in, "< molpro.out" or die "geht nicht\n"; while (<$in>){ if (/$re2/){my $x = $1} } } if ($r3){ open my $in, "< molpro.out" or die "geht nicht\n"; while (<$in>){ if (/$re3/){my $x = $1} } } }, });
1
2
3
4
Benchmark: timing 100000 iterations of extra, mit_qr, normal...
extra: 82 wallclock secs (78.87 usr + 2.58 sys = 81.45 CPU) @ 1227.75/s (n=100000)
mit_qr: 71 wallclock secs (69.35 usr + 1.29 sys = 70.64 CPU) @ 1415.63/s (n=100000)
normal: 37 wallclock secs (35.88 usr + 1.27 sys = 37.15 CPU) @ 2691.79/s (n=100000)
1 2 3 4 5 6 7 8 9 10 11 12 13
my $reg1 = 1; my $reg2 = 0; ... my @regex; push(@regex,[qr/^unleserliches\s+Konstrukt/,sub{ ... }]) if ($reg1); push(@regex,[qr/xyz/,sub{ ... }]) if ($reg2); ... while (my $line=<$dat>){ $line=~$_->[0] && $_->[1]->($line,...) for(@regex); }