Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

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

by jwkrahn (Monsignor)
on Feb 19, 2020 at 22:40 UTC ( #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
  • Comment on Re: Executing CGI/web form directives in regex substitution without pages of code
  • Download Code

Replies are listed 'Best First'.
Re^2: Executing CGI/web form directives in regex substitution without pages of code
by Polyglot (Pilgrim) 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
Node Status?
node history
Node Type: note [id://11113194]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (6)
As of 2020-03-30 11:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    To "Disagree to disagree" means to:









    Results (175 votes). Check out past polls.

    Notices?