http://qs321.pair.com?node_id=1156150


in reply to search/replace one liners without clobbering

Some thoughts:

Can you supply a short, representative chunk of the sample input data you wish to process and its desired final form? I think that would help greatly to define the problem.

Update: Various small wording and spelling fixes.


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

Replies are listed 'Best First'.
Re^2: search/replace one liners without clobbering
by f77coder (Beadle) on Feb 26, 2016 at 01:49 UTC
    sure here is an example line of code these old files have no spaces between operators but i'll space it out
    exa=cexpl ( ccosl (arg), csinl ( arg) ) * cabsl (arg2) + csqrtl ( carg +l(arg3) + csqrtl(cargl(arg4) * cargl(arg5) + cargl (arg5) * cargl(arg +5));
    result would be
    exa = exp( cos(arg) , sin(arg) ) * fabs(arg2)+ sqrt(carg(arg3)) + sqrt +(carg(arg4)*carg(arg5)+carg(arg5)*carg(arg5));
      result would be

      exa = exp( cos(arg) , sin(arg) ) * fabs(arg2)+ sqrt(carg(arg3)) + sqrt(carg(arg4)*carg(arg5)+carg(arg5)*carg(arg5));

      Really? Why do you go from cabsl to fabs instead of replacing it with abs? Also, your bracket counts seem to differ between the before and after examples.

      Assuming that you didn't mean that and really wanted abs and the same number of brackets and correcting the arbitrary whitespace:

      #!/usr/bin/env perl use strict; use warnings; use Test::More tests => 1; my $have = 'exa=cexpl ( ccosl (arg), csinl ( arg) ) * cabsl (arg2) + c +sqrtl ( cargl(arg3)) + csqrtl(cargl(arg4) * cargl(arg5) + cargl (arg5 +) * cargl(arg5));'; my $want = 'exa = exp( cos(arg) , sin(arg) ) * abs(arg2)+ sqrt(carg(ar +g3)) + sqrt(carg(arg4)*carg(arg5)+carg(arg5)*carg(arg5));'; # Remove apparently arbitrary spaces for the purposes of validation $have =~ s/ +//g; $want =~ s/ +//g; for my $term (qw/exp cos sin abs sqrt carg/) { $have =~ s/\b[cf]? ${term} [fl]?/$term/xg; } is ($have, $want, 'Match');