in reply to Regular Expression, substitution
Using your first example:
#!/usr/bin/perl use strict; use warnings; $currentSentence =~ s/[\ba\b|\ban\b|\bthe\b]//g; exit;
I get the following:
P:\>rmv1.pl Global symbol "$currentSentence" requires explicit package name at P:\ +rmv1.pl line 4. Execution of P:\rmv1.pl aborted due to compilation errors.
Then I fixed the error on line 4:
#!/usr/bin/perl use strict; use warnings; my $currentSentence =~ s/[\ba\b|\ban\b|\bthe\b]//g; exit;
Which yields the following:
P:\>rmv2.pl Use of uninitialized value $currentSentence in substitution (s///) at +P:\rmv2.pl line 4.
So, to fix that, I added a value based on your loose description:
#!/usr/bin/perl use strict; use warnings; my $currentSentence = "The big dog rolled in an open field filled with + a type of grass."; $currentSentence =~ s/[\ba\b|\ban\b|\bthe\b]//g; exit;
I get the following:
P:\>rmv3.pl P:\>
Now morbidly curioius, I added a line to display the result:
#!/usr/bin/perl use strict; use warnings; my $currentSentence = "The big dog rolled in an open field filled with + a type of grass."; $currentSentence =~ s/[\ba\b|\ban\b|\bthe\b]//g; print "[$currentSentence]\n"; exit;
I get the following:
P:\>rmv4.pl [T big dog rolld i op fild filld wi yp of grss.]
I'm now going to ask the question:
What's with all the \baction in your regular expression?
- Comment on Re: Regular Expression, substitution
- Select or Download Code
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Regular Expression, substitution
by GrandFather (Saint) on Apr 06, 2016 at 03:57 UTC | |
by AnomalousMonk (Archbishop) on Apr 06, 2016 at 05:10 UTC | |
by marinersk (Priest) on Apr 06, 2016 at 04:47 UTC |