Hello all,



I am labouring a long while already with a Perl script, and I am helpless. I
already asked on perl.beginner

http://groups.google.de/group/perl.beginners/browse_frm/thread/7b985c1ed1992
ed9/527ea76679be3ad3?lnk=raot&hl=de#527ea76679be3ad3

but got no answer, probably because my question was not clear.

I want to transform a Excel-Tabular into a LaTeX-Tabular and need to
calculate the sums for each double-line replacing the "TOTAL"-lines with the
calculated differences.

The double lines (without the TOTAL-Line) have the form:

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    &    &    &    Name2    &    Sam    \\
TOTAL    &    =SUMME(B7-B6)    &    =SUMME(C7-C6)    &    =SUMME(D7-D6)    &
=SUMME(E7-E6)    &    =SUMME(F7-F6)


etc etc

My actual script is calculating the differences only one time and replacing
the result to all following lines ... Why?

Could some Guru here help me out?


Best greetings from Munich



marek



#!/usr/bin/perl

use strict;
use warnings;

# $/ = "\nTOTAL" ;
# $/ = '';
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;";

while (<IN>) 
  {
    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.+/gi)
      {
        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); #to calculate we need to replace the
"&" with "."
        $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);
# For the LaTeX Talbe we need to replace the "." back to a "&"

      }    
    
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/g;
    print OUT;
  }


__END__
^[.\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
15.03.2007    &    88701&50    &    38585&20    &    2184    &    64&50    &
199&10    &        &        &        &    Don    \\
[.\d]+    \t&\t ([&\d]+)\t &\t ([&\d]+)\t  &\t ([\d]+)\t&\t([&\d]+)\t&\t
([&\d]+)\t.+$\n
16.03.2007    &    88868&80    &    38657&30    &    2195    &    64&50    &
328&20    
TOTAL        &                &    =SUMME(C3-C2)    &    =SUMME(D3-D2)    &
=SUMME(E3-E2)    &    =SUMME(F3-F2)




-- 
------------------------------------------------------------------------
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]>

Reply via email to