Beefy Boxes and Bandwidth Generously Provided by pair Networks Joe
Clear questions and runnable code
get the best and fastest answer
 
PerlMonks  

Re: is it possible?

by BrowserUk (Pope)
on Aug 13, 2012 at 13:44 UTC ( #987122=note: print w/ replies, xml ) Need Help??


in reply to is it possible?

Presumably, you are looking to use Perl to manipulate the source code of some assembler like language?

If so, the answer is yes. It would be a relatively simply s/// substitution.

But, in order to help you, you'll have to more clearly define

  • the circumstances under when that substitution to take place;

    Is it whenever the text ROUTINE#2 occurs (other than its definition)?

    Or only when it appears as the second parameter to the EX instruction?

    Only when it is the second argument and R1 is the first?

  • the scope of the substitutions;

    Is this all contained in one file? Multiple files?

  • Much more information.

That said, whilst it could certainly be done with Perl, you may be better off using a proper macro processor like M4 or even a C pre-compiler.

Clearer questions lead to better answers -- and stop people misinterpreting the questions.


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?


Comment on Re: is it possible?
Select or Download Code
Re^2: is it possible?
by suno (Acolyte) on Aug 14, 2012 at 05:07 UTC
    Hi,...

    Whenever "EX" instruction is there in the first column followed by 2 arguments, whatever is there in the 2nd argument will be another routine(this routine will be in the same file.). that has to be substituted in place of the entire EX statement..

      Whenever "EX" instruction is there in the first column followed by 2 arguments, whatever is there in the 2nd argument will be another routine(this routine will be in the same file.). that has to be substituted in place of the entire EX statement..

      Okay, so you would need 3 passes.

      1. Load the file into an array line-by-line: my @file = <$fh>;
      2. Scan the lines and record the routine names from the EX statements:
        my %exs; $file[ $_ ] =~ m[\s+EX\s+[^,]+,(\S+)] and push @{ $exs{ $1 } }, $_ for + 0 .. $#file;
      3. Now locate the routines referenced in the EX lines and make the substitutions:
        for my $rtn ( keys %exs ) { my $n = 0; ++$n until $file[ $n ] =~ m[$rtn\s+(\S+)]; my $subst = $1; $file[ $_ ] = "\t$subst" for @{ $exs{ $rtn } }; }
      4. Write out the modified array to a new file.

      Of course, that only deals with single line substitutions; you'd need to add error checking for routines referenced but not found; and you might want to remember the lines where the substituted routines were found and remove them before output; etc. but that should get you started.

      As OGB said; I can't believe that there isn't an ISPF macro to do this already in existance.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://987122]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (5)
As of 2014-04-19 13:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (480 votes), past polls