Hi,
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.
>
1. Your indentation is erratic.
2. See http://perl-begin.org/tutorials/bad-elements/ .
> 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" );
>
1. why did you add single quotes?
2. Perhaps use
http://perl-begin.org/tutorials/bad-elements/#re_string_interpolate
> 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
>
--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Funny Anti-Terrorism Story - http://shlom.in/enemy
Every successful open source project will eventually spawn a sub‐project.
— http://www.shlomifish.org/humour/fortunes/osp_rules.html
Please reply to list if it's a mailing list post - http://shlom.in/reply .
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/