sroux has asked for the wisdom of the Perl Monks concerning the following question:
Why the following code would replace 1 characters set out of 2, I don't get it..?
for (@lines) { s/\|\|/\|#MI\|/g }
or for (@lines) { s/ / #MI /g }
Input: EST07|E9028;CP392;ALLOC_CP392|R2021||||||||||||0.46458
Output: EST07|E9028;CP392;ALLOC_CP392|R2021|#MI||#MI||#MI||#MI||#MI||#MI|0.46458
Expected: EST07|E9028;CP392;ALLOC_CP392|R2021|#MI|#MI|#MI|#MI|#MI|#MI|#MI|#MI|#MI|#MI|#MI|0.46458
So my workaround is the following:
for (@lines) { s/\|\|/\|#MI\|/g }
for (@lines) { s/\|\|/\|#MI\|/g }
or for (@lines) { s/ / #MI /g } for (@lines) { s/ / #MI /g } Thank you for your wisdom. SRX
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Substitution is replacing one character set out of two
by hippo (Archbishop) on Apr 01, 2022 at 11:19 UTC | |
by sroux (Sexton) on Apr 01, 2022 at 11:37 UTC | |
by hippo (Archbishop) on Apr 01, 2022 at 12:10 UTC | |
by sroux (Sexton) on Apr 01, 2022 at 12:33 UTC | |
Re: Substitution is replacing one character set out of two
by choroba (Cardinal) on Apr 01, 2022 at 10:58 UTC |