http://www.perlmonks.org?node_id=987265


in reply to Re: is it possible?
in thread is it possible?

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..

Replies are listed 'Best First'.
Re^3: is it possible?
by BrowserUk (Patriarch) on Aug 14, 2012 at 14:20 UTC
    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?