On Wed, 2018-06-13 at 21:21 -0500, Martin McCormick wrote:
> I wrote a small perl program to more quickly read all the
> subjects in an email list.  One of the things the script does is
> to remove the mailing list name which repeats for every message
> and consists of a [, some English text and finally a ].
> 
>       I was able to write a RE that identifies that text and
> cause the script to save that string in a variable called
> $remove.  That part works and looks like:
> 
>     foreach my $field (@fields) {    #Assemble the new subject.
> if($field =~ m/\[(.*?)\]/) 

if you want to remove this string then why not just remove it here:

if ( $field =~ s/\[(.*?)\]// )


> { #$field is the blocked field.
> $remove = $field;
> } #field is the blocked field.
> else
> { #$field is not the blocked string.
>         $newest = $newest . $field;
> } #$field is not the blocked string.
>     }    #Assemble the new subject.
> 
>     if ( $newest eq $previous ) {    #Skip this iteration.
>         $newest = "";
>         next;
>     }    #Skip this iteration.
> else
> { #they are different.
> 
>       This is where things don't quite work yet.  At this
> point, I have $remove which contains that bracketted list name
> such as
> 
> [BLIND-HAMS] or any number of other names enclosed in brackets.
> So, the next thing I do is to attempt to remove just that part of
> the subject line, keeping everything else that was there.
> 
>    $subject =~ s/'$remove'//;

After string interpolation you have:

    $subject =~  s/'[BLIND-HAMS]'//;

Which is a string of three characters consisting of the "'" character
followed by a character class followed by the "'" character.

The character class says to match one character that is either 'A' or
'B' or 'D' or 'E' or 'F' or 'G' or 'H' or 'I' or 'L' or 'M' or 'N' or
'S'.

You probably need to use quotemeta:

    $subject =~  s/'\Q$remove\E'//;



John

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to