Thread Parameter umwandeln (55 answers)
Opened by Benji2010 at 2010-12-13 12:04

Gast wer
 2010-12-13 14:13
#143519 #143519
Code (perl): (dl )
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
#!/usr/bin/perl
use strict;
use warnings;
my %vars;
while(my $line=<DATA>)
{
  # Zeile berechnen wenn Rexexp matched
  my @calc;
  $line=~s/(\w+)=(\S+)/push(@calc,[$1,$2]); $_="##$#calc##"/eg;
  # etwas gefunden
  if(@calc)
  {
    for(0..$#calc)
    {
      my $k=$calc[$_][0];
      my $v=$calc[$_][1];

      # es ist ein Berechnung
      if($v=~/^(?:R|-|\+|\d)/)
      {
        # variablen durch konstante ersetzen
        $v=~s/(R\d+)/$vars{$1}/g;

        # berechnen
        $v=eval($v);
      }

      # variablenzuweisung
      $vars{$1}=$v if($k=~/(R\d+)/);

      # Ersetzung Rückgängig machen
      $line=~s/##$_##/$k=$v/g;
    }
  }

  # Zeile Ausgeben
  print $line;
}

__DATA__
N3070 MSG ( "TEST")
N3080 G95 S100 M3 f0.2
N3090 G0 Z200
N3100 X=0 Y=-630 C=DC(0)
N3110 M8
N3120 R12=30
N3121 R14=40
N3122 X=R12+R14
N490 R53=800 R52=50
N500 X=R53 Y=-R52-40
N609 R23=100 R53=10
N610 R24=R23/(R53*2)

Last edited: 2010-12-13 14:23:04 +0100 (CET)

View full thread Parameter umwandeln