Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw

data manipulation

by ng0177 (Acolyte)
on Feb 28, 2021 at 15:00 UTC ( #11128907=perlquestion: print w/replies, xml ) Need Help??

ng0177 has asked for the wisdom of the Perl Monks concerning the following question:

Hello Monks,

rather than resorting to anything else, I would like to write a data manipulation script in perl. The task is as follows, see attached data file:

1. find and read vector of 36 (or n) values Opt.OptGBM.Parameters starting with 0.1

2. overwrite 36 (or n) numbered triple line block lower and upper values of Opt.OptGBM.Design.OptParam.001.Name with a percentage e.g. +/- 10% of the vector value for

lower: vector*(1+vector*percentage) and
upper: vector*(1-vector*percentage)

I can go ahead and refresh my knowledge, if anyone may give some guidance.

Appreciate, Thomas

... ... Opt.OptGBM.Parameters = 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1. +2 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 0.1 0.2 0.3 0.4 0.5 + 0.6 0.7 0.8 0.9 1.0 1.1 1.2 ... ... Opt.OptGBM.Design.OptParam.001.Name = RadialTurbine.Ge +o.Wheel.Blade.Hub.Theta.Point.1.Y.Opt Opt.OptGBM.Design.OptParam.001.LowerLimitFormula = -1. Opt.OptGBM.Design.OptParam.001.UpperLimitFormula = 2. Opt.OptGBM.Design.OptParam.002.Name = RadialTurbine.Ge +o.Wheel.Blade.Hub.Theta.Point.2.Y.Opt Opt.OptGBM.Design.OptParam.001.LowerLimitFormula = -1. Opt.OptGBM.Design.OptParam.001.UpperLimitFormula = 2. ... ...

Replies are listed 'Best First'.
Re: data manipulation
by BillKSmith (Monsignor) on Feb 28, 2021 at 21:27 UTC
    It really is not possible to overwrite data in file. You must replace the file with edited version of itself. (This would be true of any language) The perl runtime flags /p and /i should be a big help in doing this.

    Process the file one line at a time.

    • If the current line is a 'Parameters' line, extract the vector into a global array.
    • Else if it is a 'Name' line, extract the block number into a global scalar.
    • Else if it is a 'LowerLimit' line, update the value. (use $vector[$block])
    • Else if it is a 'UpperLimit' line, update the value.
    • Else do nothing

    If you still have problems, post explicit questions.

Re: data manipulation
by kcott (Archbishop) on Feb 28, 2021 at 17:13 UTC

    G'day Thomas,

    Sorry mate. None of this looks like Perl. Frankly, I'm hard-pressed to think of a non-Perl syntax where this would be valid. Of course, a hoard of Perl-poets may claim this to be untenable and prove me wrong; all good!

    Please see "Short, Self-Contained, Correct Example" for a better way to present your question.

    — Ken

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11128907]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (1)
As of 2022-07-03 01:52 GMT
Find Nodes?
    Voting Booth?
    My most frequent journeys are powered by:

    Results (103 votes). Check out past polls.