Hi Dmitri,

On Thu, 14 Jun 2018 11:34:34 +0300
Дмитрий Ананьевский <dime...@impulse-kiev.in.ua> wrote:

> On Wed, 13 Jun 2018 21:21:12 -0500
> "Martin McCormick" <marti...@suddenlink.net> 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/\[(.*?)\]/) 
> > { #$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'//;
> >     print( $subject, "\n" );
> > 
> >     The example, here is the closest thing to anything
> > happening.  In the case of [BLIND-HAMS] the B is gone but the
> > brackets and everything else remains
> > 
> >     I looked around for examples of similar code and found
> > 
> > $subject =~ s/$remove\K.*?(?=\d+)//;
> > 
> > It looks like it should keep everything else in the $subject
> > string except [BLIND-HAMS] but it keeps everything including that
> > so there is no change.
> > 
> >     I actually think I am close but the line with the
> > brackets may be confusing the shell although single and double
> > quotes don't make any difference.
> > 
> >     I also may have damaged that last example when I modified
> > it to work with a string called $subject which is the whole
> > subject line and $remove which is the part I am trying to remove.
> > 
> >     The rest of the script appears to work and is designed to
> > only list the first message in a list of N messages of the same
> > subject. so, if there are 120 messages with the subject of "how
> > did you spend your Summer?", I read the first of those subject
> > lines and none until the first message that doesn't have that
> > title.
> > 
> > Any constructive ideas are appreciated.  Thank you.
> > 
> > Martin McCormick
> > 
> > -- 
> > To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> > For additional commands, e-mail: beginners-h...@perl.org
> > http://learn.perl.org/
> > 
> >   
> 
> I think it's because you have 
> 
> $subject =~ s/[BLIND-HAMS]//;
> 
> and it deletes first appeared symbol from the diapason.
> 

https://en.wiktionary.org/wiki/diapason - perhaps you mean "character class".

> You can try smth like $remove =~ s/([\[\]])/\\$1/g;
> 

Why not use http://perldoc.perl.org/functions/quotemeta.html ?

--
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