$channel_data =~ s@\[@<lftsqbrk/>@g; $channel_data =~ s@\]@<rtsqbrk/>@g; $channel_data =~ s@\(@<lftbrk/>@g; $channel_data =~ s@\)@<rtbrk/>@g; $channel_data =~ s@\+@<plus/>@g; $channel_data =~ s@\?@<ques/>@g; $channel_data =~ s@\'@<apos/>@g; $channel_data =~ s@\$@<dollar/>@g;
All those bindings look clumsy and people often like to use a one-shot for loop:
for ($channel_data) { s@\[@<lftsqbrk/>@g; s@\]@<rtsqbrk/>@g; s@\(@<lftbrk/>@g; s@\)@<rtbrk/>@g; s@\+@<plus/>@g; s@\?@<ques/>@g; s@\'@<apos/>@g; s@\$@<dollar/>@g; }
Also, you may want to maintain a "hash of substitutions" and generate the pattern:
# Outside the loop my %subst = ( '[' => '<lftsqbrk/>', ']' => '<rtsqbrk/>', '(' => '<lftbrk/>', ')' => '<rtbrk/>', '+' => '<plus/>', '?' => '<ques/>', ''' => '<apos/>', '$' => '<dollar/>', ); my $re=join '|', map quotemeta, keys %subst; # ... # Inside the loop $channel_data =~ s/($re)/$subst{$1}/g;
In reply to Re: Modernisation Needed
by blazar
in thread Modernisation Needed
by simonodell
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |