Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Help to create a program

by fair (Initiate)
on May 12, 2022 at 20:00 UTC ( #11143849=perlquestion: print w/replies, xml ) Need Help??

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

Greetings happily!
I want to open a document and it contains all lines like
int n = read("Swaps\\test" + to_string(t) + ".txt");
replace with
string tymchasovyi("Swaps\\test" + to_string(t) + ".txt"); int n = read(tymchasovyi);
The contents inside the parentheses must be transferred correctly. I want help.

Replies are listed 'Best First'.
Re: Help to create a program
by AnomalousMonk (Archbishop) on May 12, 2022 at 20:51 UTC
Re: Help to create a program
by stevieb (Canon) on May 12, 2022 at 20:03 UTC
    I want help.

    It doesn't appear that way to me. You've provided no information whatsoever with what you've already tried, therefore what you want here is for someone to completely do your work.

    This site is for getting help with programming issues. We will not do your work for free. In order to provide help with a programming issue, we need to see your program, and you also need to explain what's supposed to be happening, and a problem description as to what's happening that you don't expect.

      I do not know which tools are best to use. I have no skill in PERL. I think the decision is far from difficult. But I will look for the right way more than one day.

        G'day fair,

        Welcome to the Monastery.

        Your first foray here has drawn the ire of a number of monks. I can see you've garnered a number of downvotes. Anything along the lines of "I want help", "Show me code", and such like, will get similar responses to what you've received here.

        We're more than happy to help anyone who's shown some effort; however, this is not a code writing service.

        "I have no skill in PERL."

        None of us left the womb with any skill in Perl. Like other skills, it requires learning and practice. By the way, the language is called Perl; the program to run Perl programs is perl (possibly with an extension such as .exe depending on the OS); "PERL" is not a thing.

        I suggest you start with "perlintro: Perl introduction for beginners". Bookmark the "online documentation". Take a look at its Tutorials section; in particular, the FAQ links.

        — Ken

        From the brief glimpse you've given of the problem domain, it seems as if you're looking for a recursive descent parser. Maybe take a look at Parse::RecDescent (and possibly Parse::RecDescent::FAQ although I have no experience with this module/document) or Marpa::R2.

        Give a man a fish:  <%-{-{-{-<

Re: Help to create a program
by karlgoethebier (Abbot) on May 13, 2022 at 06:39 UTC

    Probably the IDE or editor of your choice is the better tool for this task. See Refactoring, Keyboard Macros and Query Replace for further inspiration.

    Regards, Karl

    «The Crux of the Biscuit is the Apostrophe»

      I really like your idea. I am also not convinced at all that any programming is required at all. This appears to be a "one off" modification of a file - not some sort of thing that will be regularly done.

      If the user is on Windows, I would suggest Notepad+ as a freeware editor. I use TextPad which is a "pay for" program, but I think similar to NotePad+. TextPad 4 from 25 years ago implements essentially the s/regex/regex/ functionality in the edit window. I have been offered an upgrade to TextPad 8, but I haven't bothered because what I have works fine.

      I suspect that some "human guided" modification of the file using a good decades old editor will get the job done faster than trying to write some general purpose program.

      Update: My attention span for this is perhaps 5-10 substitutions. I do those on a "review then approve" basis. After I have seen the regex work correctly for the first 5-10 or so cases in a row, then I turn the editor free to do the rest of the file without my explicit approval for each modification. Sometimes a very weird case is missed. If so then I fix that one again manually. Of course since this is being done in an editor, you can back out of any and all changes before saving the modified file.

      The OP does not present a clear spec on what is allowed and what is not allowed - there is no "spec".

Re: Help to create a program
by hippo (Bishop) on May 13, 2022 at 08:49 UTC
Re: Help to create a program
by GrandFather (Saint) on May 12, 2022 at 21:14 UTC

    What you show is C++ or a closely related language. It is not Perl. Even if you had asked a coherent question with comprehensive context, PerlMonks is not the appropriate support forum for you. You could try posting an updated version of your question on StackOverflow. Take note of the rel=plies you received here before you post elsewhere however. Taking time to improve your question as suggested is likely to help a lot with getting useful programming help.

    Update: Sorry, I didn't read your question closely enough the first time through and thought you were asking a question about the code itself. So, what everyone else has said: show us what you have tried and how it went wrong. If you have tried nothing we can't help you fix it.

    Optimising for fewest key strokes only makes sense transmitting to Pluto or beyond
Re: Help to create a program
by Anonymous Monk on May 12, 2022 at 22:17 UTC

    maybe something like this:

    use strict; use warnings; { my $template = <<'EOF'; string tymchasovyi(%PROMPT%); int %VARIABLE% = read(tymchasovyi); EOF sub populate_template { my($v,$p) = @_; my $t = $template; $t =~ s/%VARIABLE%/$v/g; $t =~ s/%PROMPT%/$p/g; $t } } for ( @lines ) { s(\bint\s+(\w+)\s*=\s*read\s*\((.*)\)\s*;){ populate_template($1,$ +2) }e; }

    but caveat that if you have more than one of those in the same scope, you'll get 'redefined variable' warnings.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others having an uproarious good time at the Monastery: (3)
As of 2023-06-08 01:47 GMT
Find Nodes?
    Voting Booth?
    How often do you go to conferences?

    Results (29 votes). Check out past polls.