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

Re: Executing CGI/web form directives in regex substitution without pages of code

by jwkrahn (Abbot)
on Feb 19, 2020 at 22:40 UTC ( [id://11113194]=note: print w/replies, xml ) Need Help??


in reply to Executing CGI/web form directives in regex substitution without pages of code

Perhaps this would work better:

sub processReplacements { my ( $regexM, # TERM(S) TO MATCH $regexR, # REPLACEMENT TERM $regexI, # FLAG FOR CASE-INSENSITVE SUBSTITUTION $sv, # $sv => START, E.G. /^(.*)/; $ev, # $ev => END, E.G. /(.*)$/; $ww, # $ww => WHOLE-WORD, E.G. /\b(.*)\b/; $ch, # $ch => DELIMIT CHARS, # E.G. /[.,:;!?'"](.*)[.,:;!?'"]/; @data ) = @_; # INCOMING ARRAY my @changed; # OUTGOING ARRAY my $linehead = ''; my $sourceline = ''; $regexM = decode( 'utf8', $regexM ); $regexR = decode( 'utf8', $regexR ); my $regex = '(?' . ( $regexI ? 'i' : '' ) . ':' . ( $sv ? '^' : $ww ? '\b' : '' ) . ( $ch ? "[$ch]" : '' ) . $regexM . ( $ch ? "[$ch]" : '' ) . ( $ev ? '$' : $ww ? '\b' : '' ) . ')'; foreach my $line ( @data ) { chomp $line; $line =~ s/\s+$//; $linehead = $1 if $line =~ s/((?:\d+\t)+)//; # KEEP A COPY OF ORIGINAL FOR LATER COMPARISON $sourceline = $line; $line =~ s/$regex/$regexR/ge; if ( $line ne $sourceline ) { push @changed, "$linehead$sourceline\t$line\n"; } $line = $linehead . $line; } return @changed; } # END SUB processReplacements

Replies are listed 'Best First'.
Re^2: Executing CGI/web form directives in regex substitution without pages of code
by Polyglot (Chaplain) on Feb 19, 2020 at 23:03 UTC

    Thank you! With one minor correction (a missed semicolon), this code works. I'd be happy to upvote it again if I could. You took the time to show me some better ways of doing things, such as the incoming variable assignments, that I had not seen before. (Sometimes I think I'm just an old plugger.)

    Thank you for taking your time to help me with this. Code like this will be much easier to adjust and maintain than what I had before.

    Blessings,

    ~Polyglot~

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-03-29 11:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found