Siegfried Heintze wrote:
This piece of code works, but it has a redundant pattern in it. Every time I
try to create a variable "my $pRole = qr/Assistant|Executive|Senior//;"
That won't work because of the syntax error, you have an extra '/' character
at the end. That should be:
my $pRole = qr/Assistant|Executive|Senior/i;
to replace the redundant patterns, it stops working. It has something to do
with the "gi" qualifiers for the patterns. Can someone edit this code to use
What makes you think that the "gi" options have anything to do with it?
the variable $pRole instead of multiple occurrences of
/Assistant|Executive|Senior/?
#!c:\Perl\bin\perl.exe
# Begin commands to execute this file using Perl with bash
# ./test.pl
# End commands to execute this file using Perl with bash
my $sJobTitle = "Wanted: Senior Assistant for Corporate Executive";
while(my @m = $sJobTitle =~ /Assistant|Executive|Senior/gi){
$sJobTitle =~ s/Assistant|Executive|Senior//i;
print __LINE__. " m=[".join(",",@m)."]\n";
$x{$m[0]} = 0;
}
print $sJobTitle."(".join(",",sort keys %x).")\n";
If you want to do that with a single regular expression you _could_ do it like
this:
my $sJobTitle = 'Wanted: Senior Assistant for Corporate Executive';
my %x;
$sJobTitle =~ s/(Assistant|Executive|Senior)/ $x{ $1 } = (); '' /gie;
print "$sJobTitle(" . join( ',', sort keys %x ) . ")\n\n";
Or to use the example in the FAQ which is faster then using alternation in the
regular expression:
my $sJobTitle = 'Wanted: Senior Assistant for Corporate Executive';
my @words = qw( Assistant Executive Senior );
my %x;
for my $word ( @words ) {
$x{ $word } = () if $sJobTitle =~ s/$word//gi;
}
print "$sJobTitle(" . join( ',', sort keys %x ) . ")\n\n";
John
--
use Perl;
program
fulfillment
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>