
Chupo_cro
Novice

Aug 19, 2012, 7:23 PM
Post #6 of 11
(23852 views)
|
Re: [Laurent_R] Read the var values
[In reply to]
|
Can't Post
|
|
Hello, Am I correct understanding that: mean that X = 200.18, Y = 50.41 and Z = 42.78? Yes, that is correct. The '=' is optional and optional spaces are allowed after the X, Y, or Z. The text is in fact G-code. However, different CNC machines may use different syntax, hence the '=' is optional. The lines I made for the testing purposes are purposely made to reflect as many as possible allowed variations.
Given that X, Y and Z are not always in the same order, I would probably use three distinct regexes on each line of input. Assuming you line is in $_, something like this: $X = $1 if /X=?([\d]+)/; $Y = $1 if /Y=?([\d]+)/; $Z = $1 if /Z=?([\d]+)/; Thank you very much! I found this information very useful!! And, BTW, it might seem costly, but using 3 simple regexes is not necessarily more expensive that a single complicated one that is far more likely to require a lot of backtracking. The regexes above take into account an optional '=' sign between the letter and the numbers. You could also decide to remove the equal sign before stating your matches: s/=//g; # removes the "=" characters $X = $1 if /X([0-9]+)/; $Y = $1 if /Y([0-9]+)/; # ... Thank you very much for your help! Regards Chupo_cro
(This post was edited by Chupo_cro on Aug 19, 2012, 7:48 PM)
|