On 12.04.2007 18:16, "Ronald J Kimball" <[EMAIL PROTECTED]> wrote:
>
> If you set $/ to undef, then you're asking Perl to read in the entire input
> all at once. Therefore, your loop only executes once, your m//g only
> matches once, and your s///g replaces every entry with the results
> from that one match.
this I don't understand! m//g should find ALL matches, also in a file read
in at once, because of the g (=global) modifier ???
>
> Now, I see you're setting $/ to undef because you need to operate on two
> lines at a time. What you want to do then is change how you have set up
> the loop, for example:
>
> #!perl
>
> undef $/;
>
> $_ = <IN>;
>
> 1 while s{...}{
> # calculate the total, and create the string to replace
> # everything that was matched
> }gie;
>
> print OUT;
>
> __END__
>
>
> Another, possibly clearer, way would be to read in two lines each time
> through the loop:
>
> #!perl
>
> # don't undef $/
>
> while (<IN>) {
> $_ .= <IN>; # read in the next line as well
>
> if (m/.../i) {
> # calculate the total
> s/.../.../;
> }
>
> print OUT;
> }
>
> __END__
>
>
> Ronald
Thank you so much! As often, Ronald our Perl-Guru is answering :-)
I tried both suggestions; but it is replacing nothing! First script, after
modification, looks like follows:
#!/usr/bin/perl
use strict;
use warnings;
undef $/;
my $in = "excel_autorech.tex";
open IN, "$in" or die "Error! $!\n;";
my $out = "excel_autorech_out.tex";
open OUT, ">$out" or die "Error! $!\n;";
$_ = <IN>;
my ($km1_dif, $km2_dif, $stiche_dif, $zschl_dif, $sum_dif);
1 while
s{/[.\d]+\t&\t([&\d]+)\t&\t([&\d]+)\t&\t([\d]+)\t&\t([&\d]+)\t&\t([&\d]+)\t&
\t&\t&\t&\t[A-Z]+\t\\\\\n[.\d]+\t&\t([&\d]+)\t&\t([&\d]+)\t&\t([\d]+)\t&\t([
&\d]+)\t&\t([&\d]+)\t.+/i}{
my ($km1_1, $km2_1, $stiche_1, $zschl_1, $sum_1, $km1_2, $km2_2,
$stiche_2, $zschl_2, $sum_2) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);
tr/&/./ for ($km1_1, $km2_1, $stiche_1, $zschl_1, $sum_1, $km1_2,
$km2_2, $stiche_2, $zschl_2, $sum_2);
$km1_dif = sprintf ("%.2f",$km1_2 - $km1_1);
$km2_dif = sprintf ("%.2f",$km2_2 - $km2_1);
$stiche_dif = $stiche_2 - $stiche_1;
$zschl_dif = sprintf ("%.2f",$zschl_2 - $zschl_1);
$sum_dif = sprintf ("%.2f",$sum_2 - $sum_1);
tr/./&/ for ($km1_dif, $km2_dif, $stiche_dif, $zschl_dif, $sum_dif);
s/TOTAL\t.+/TOTAL\t&\t$km1_dif\t&\t$km2_dif\t&\t$stiche_dif\t&\t$zschl_dif\t
&\t$sum_dif\t/}gie;
print OUT;
__END__
I tried your second suggestion, but it is not working either! Suppose
because in my <IN> file, the lines are not regular ... So if I read in two
lines by two lines, it will sometimes match the double line, we are looking
for, but sometimes not, depending the empty lines between ... (I will paste
the entire <IN> file at the end) ...
First the modified script looks like that; perhaps there is an
misunderstanding?
#!/usr/bin/perl
use strict;
use warnings;
my $in = "excel_autorech.tex";
open IN, "$in" or die "Error! $!\n;";
my $out = "excel_autorech_out.tex";
open OUT, ">$out" or die "Error! $!\n;";
while (<IN>)
{
$_ .= <IN>;
# next if (/^$/g);
my ($km1_dif, $km2_dif, $stiche_dif, $zschl_dif, $sum_dif);
if
(m/[.\d]+\t&\t([&\d]+)\t&\t([&\d]+)\t&\t([\d]+)\t&\t([&\d]+)\t&\t([&\d]+)\t&
\t&\t&\t&\t[A-Z]+\t\\\\\n[.\d]+\t&\t([&\d]+)\t&\t([&\d]+)\t&\t([\d]+)\t&\t([
&\d]+)\t&\t([&\d]+)\t.+/i)
{
my ($km1_1, $km2_1, $stiche_1, $zschl_1, $sum_1, $km1_2, $km2_2,
$stiche_2, $zschl_2, $sum_2) = ($1, $2, $3, $4, $5, $6, $7, $8, $9, $10);
tr/&/./ for ($km1_1, $km2_1, $stiche_1, $zschl_1, $sum_1, $km1_2,
$km2_2, $stiche_2, $zschl_2, $sum_2);
$km1_dif = sprintf ("%.2f",$km1_2 - $km1_1);
$km2_dif = sprintf ("%.2f",$km2_2 - $km2_1);
$stiche_dif = $stiche_2 - $stiche_1;
$zschl_dif = sprintf ("%.2f",$zschl_2 - $zschl_1);
$sum_dif = sprintf ("%.2f",$sum_2 - $sum_1);
tr/./&/ for ($km1_dif, $km2_dif, $stiche_dif, $zschl_dif, $sum_dif);
s/TOTAL\t.+/TOTAL\t&\t$km1_dif\t&\t$km2_dif\t&\t$stiche_dif\t&\t$zschl_dif\t
&\t$sum_dif\t/;
}
print OUT;
}
__END__
Here the <IN> file; for LaTeX-Gurus here, the table is in work and will not
"compile" ...
\documentclass[a4paper]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage{longtable}
\usepackage{array}
\usepackage{color}
\clubpenalty = 10000
\widowpenalty = 10000
\begin{document}
Fahrer\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\hfill{Monat}\_\_\_\_\_\_\_\
_\_\_\_\_\_\_\_\_\_\_\_\_\_
\newcommand{\bold}{\bfseries}
\newcolumntype{D}{>[EMAIL PROTECTED]>{\color{blue}}l}
\newcolumntype{A}{>[EMAIL PROTECTED]>{\color{green}}l}
\begin{longtable}[c]{| >{\bold}c | >{\bold}A | >{\bold}D | >{\bold}c |
>{\bold}D | >{\bold}A | >{\bold}c | >{\bold}c | >{\bold}c | >{\bold}c |
>{\bold}c |}
\hline
\multicolumn{15}{| >{\bold}c |}{Abrechnung von 11.11.2007 bis 30.22.2007}
\\
\hline
\multicolumn{10}{| >{\bold}c }{} & \multicolumn{3}{| >{\bold}c
|}{Arbeitszeit} & \multicolumn{2}{| >{\bold}c |}{}\\
\hline
Datum & \multicolumn{2}{ | >{\bold\color{green}}c | }{KM T} &
\multicolumn{2}{ | >{\bold\color{blue}}c | }{KM B} & RI & \multicolumn{2}{ |
>{\bold\color{blue}}c | }{km OR} & \multicolumn{2}{ | >{\bold\color{green}}c
| }{km SB} & B & E & Std & Fahrer & Tag \\
\hline
\gdef\bold{\normalfont}\bold
15.03.2007 & 88701&50 & 38585&20 & 2184 & 64&50 &
199&10 & & & & Don \\
16.03.2007 & 88868&80 & 38657&30 & 2195 & 64&50 &
328&20 & & & Name1 & Fre \\
TOTAL & =SUMME(C3-C2) & =SUMME(D3-D2) & =SUMME(E3-E2) &
=SUMME(F3-F2)
16.03.2007 & 88868&80 & 38657&30 & 2195 & 64&50 &
328&20 & & & & Fre \\
17.03.2007 & 88868&80 & 38657&30 & 2195 & 64&50 &
328&20 & & & Name1 & Sam \\
TOTAL & =SUMME(B7-B6) & =SUMME(C7-C6) & =SUMME(D7-D6) &
=SUMME(E7-E6) & =SUMME(F7-F6)
17.03.2007 & 88868&80 & 38657&30 & 2195 & 64&50 &
328&20 & & & & Sam \\
18.03.2007 & 89081&50 & 38768&20 & 2216 & 64&50 &
573&30 & & & Name2 & Son \\
TOTAL & =SUMME(B11-B10) & =SUMME(C11-C10) &
=SUMME(D11-D10) & =SUMME(E11-E10) & =SUMME(F11-F10)
18.03.2007 & 89081&50 & 38768&20 & 2216 & 64&50 &
573&30 & & & & Son \\
19.03.2007 & 89276&40 & 38859&80 & 2221 & 64&50 &
737&40 & & & Name1 & Mon \\
TOTAL & =SUMME(B15-B14) & =SUMME(C15-C14) &
=SUMME(D15-D14) & =SUMME(E15-E14) & =SUMME(F15-F14)
19.03.2007 & 89276&40 & 38859&80 & 2221 & 64&50 &
737&40 & & & & Mon \\
20.03.2007 & 89528&00 & 38975&20 & 2225 & 64&50 &
904&20 & & & Name1 & Die \\
TOTAL & =SUMME(B19-B18) & =SUMME(C19-C18) &
=SUMME(D19-D18) & =SUMME(E19-E18) & =SUMME(F19-F18) & 88
& =SUMME(F20+G20)
20.03.2007 & 89528&00 & 38975&20 & 2225 & 64&50 &
904&20 & & & & Die \\
21.03.2007 & 89773&20 & 39118&10 & 2229 & 64&50 &
1107&20 & & & Name1 & Mit \\
TOTAL & =SUMME(B23-B22) & =SUMME(C23-C22) &
=SUMME(D23-D22) & =SUMME(E23-E22) & =SUMME(F23-F22)
21.03.2007 & 89773&20 & 39118&10 & 2229 & 64&50 &
1107&20 & & & & Mit \\
22.03.2007 & 90115&60 & 39204&60 & 2233 & 64&50 &
1243&00 & & & Name1 & Don \\
TOTAL & =SUMME(B27-B26) & =SUMME(C27-C26) &
=SUMME(D27-D26) & =SUMME(E27-E26) & =SUMME(F27-F26) & 150
& =SUMME(F28+G28)
22.03.2007 & 90115&60 & 39204&60 & 2233 & 64&50 &
1243&00 & & & & Don \\
23.03.2007 & 90268&40 & 39234&50 & 2235 & 64&50 &
1292&40 & & & Name1 & Fre \\
TOTAL & =SUMME(B31-B30) & =SUMME(C31-C30) &
=SUMME(D31-D30) & =SUMME(E31-E30) & =SUMME(F31-F30)
23.03.2007 & 90268&40 & 39234&50 & 2235 & 64&50 &
1292&40 & & & & Fre \\
24.03.2007 & 90358&80 & 39275&20 & 2242 & 64&50 &
1381&30 & & & Name2 & Sam \\
TOTAL & =SUMME(B35-B34) & =SUMME(C35-C34) &
=SUMME(D35-D34) & =SUMME(E35-E34) & =SUMME(F35-F34)
24.03.2007 & 90358&80 & 39275&20 & 2242 & 64&50 &
1381&30 & & & & Sam \\
24.03.2007 & 90413&00 & 39292&60 & 2247 & 64&50 &
1427&80 & & & Name1 & Sam \\
TOTAL & =SUMME(B39-B38) & =SUMME(C39-C38) &
=SUMME(D39-D38) & =SUMME(E39-E38) & =SUMME(F39-F38)
24.03.2007 & 90413&00 & 39292&60 & 2247 & 64&50 &
1427&80 & & & & Sam \\
25.03.2007 & 90632&10 & 39391&00 & 2267 & 64&50 &
1654&40 & & & Name2 & Son \\
TOTAL & =SUMME(B43-B42) & =SUMME(C43-C42) &
=SUMME(D43-D42) & =SUMME(E43-E42) & =SUMME(F43-F42)
25.03.2007 & 90632&10 & 39391&00 & 2267 & 64&50 &
1654&40 & & & & Son \\
26.03.2007 & 90932&90 & 39505&30 & 2271 & 64&50 &
1820&00 & & & Name1 & Mon \\
TOTAL & =SUMME(B47-B46) & =SUMME(C47-C46) &
=SUMME(D47-D46) & =SUMME(E47-E46) & =SUMME(F47-F46) &
65&00 & =SUMME(F48+G48)
TOTAL/Name2 & =SUMME(B12+B36+B44) & =SUMME(C12+C36+C44) &
=SUMME(D12+D36+D44) & =SUMME(E12+E36+E44) & =SUMME(F12+F36+F44)
& =SUMME(G12+G36+G44)
TOTAL/Name1 & =SUMME(B4+B8+B16+B20+B24+B28+B32+B40+B48) &
=SUMME(C4+C8+C16+C20+C24+C28+C32+C40+C48) &
=SUMME(D4+D8+D16+D20+D24+D28+D32+D40+D48) &
=SUMME(E4+E8+E16+E20+E24+E28+E32+E40+E48) &
=SUMME(F4+F8+F16+F20+F24+F28+F32+F40+F48) &
=SUMME(G4+G8+G16+G20+G24+G28+G32+G40+G48) & =SUMME(F79+G79)
TOTAL/1423 & =SUMME(B4+B8+B12+B16+B20+B24+B28+B32+B36+B40+B44+B48)
& =SUMME(C4+C8+C12+C16+C20+C24+C28+C32+C36+C40+C44+C48) &
=SUMME(D4+D8+D12+D16+D20+D24+D28+D32+D36+D40+D44+D48) &
=SUMME(E4+E8+E12+E16+E20+E24+E28+E32+E36+E40+E44+E48) &
=SUMME(F4+F8+F12+F16+F20+F24+F28+F32+F36+F40+F44+F48) & &
=SUMME(F78+H79)
--
___________________________________________
the embassy for talented young musicians
Podium International | Marek Stepanek | [EMAIL PROTECTED]
http://www.PodiumInternational.org
___________________________________________
--
------------------------------------------------------------------------
Have a feature request? Not sure the software's working correctly?
If so, please send mail to <[EMAIL PROTECTED]>, not to the list.
List FAQ: <http://www.barebones.com/support/lists/bbedit_script.shtml>
List archives: <http://www.listsearch.com/bbeditscripting.lasso>
To unsubscribe, send mail to: <[EMAIL PROTECTED]>