Matching subsets of two strings

J

Jim Weeb

Can anyone offer some help with perl and a script operating a
mail2news gateway?

I'm using CPAN module email:simple so, I can get the groups into
variables using:

$newsgroups=$mail->header("Newsgroups");
$followupto=$mail->header("Followup-To");

Now, when processing the message, I only want to allow
followupto groups that are present in newsgroups - not any
alternative group(s). Group(s) in followupto may be listed in a
different order to those in the original newsgroups line.

I guess I need to combine the groups in each variable into an
array:

@newsgroups2 = split /,/ , $newsgroups ;
@followupto2 = split /,/ , $followupto ;

and then somehow see which items are in both arrays and write
those that are to a new variable $followupto3 (or even back to
the original $followupto)

I guess it would be done with two nested loops, however someone
previously mentioned something about a hash with regard to a
similar problem (and lost me completely). It could probably all
be done in one or two lines by a perl boffin, but unfortunately
my perl, although improving slowly, isn't quite up to the task.

Thanks.
 
A

Anno Siegel

Jim Weeb said:
Can anyone offer some help with perl and a script operating a
mail2news gateway?

I'm using CPAN module email:simple so, I can get the groups into
variables using:

$newsgroups=$mail->header("Newsgroups");
$followupto=$mail->header("Followup-To");

Now, when processing the message, I only want to allow
followupto groups that are present in newsgroups - not any
alternative group(s). Group(s) in followupto may be listed in a
different order to those in the original newsgroups line.

I guess I need to combine the groups in each variable into an
array:

@newsgroups2 = split /,/ , $newsgroups ;
@followupto2 = split /,/ , $followupto ;

and then somehow see which items are in both arrays and write
those that are to a new variable $followupto3 (or even back to
the original $followupto)

I guess it would be done with two nested loops, however someone
previously mentioned something about a hash with regard to a
similar problem (and lost me completely). It could probably all
be done in one or two lines by a perl boffin, but unfortunately
my perl, although improving slowly, isn't quite up to the task.

See the faq "How do I compute the difference of two arrays? ..."
(perldoc -q difference).

Anno
 
J

Jim Weeb

See the faq "How do I compute the difference of two arrays? ..."
(perldoc -q difference).

Thanks, that appears to tell me the differences (although I'm n
ot quite sure what values it puts in what arrays, I'll have to
run it and find out). That's a slightly different problem than I
have - I want to know which elements of array2 ARE present in
array1.
 
T

Tad McClellan

and then somehow see which items are in both arrays


So, you want the intersection of the two arrays.

perldoc -q intersection

How do I compute the difference of two arrays? How do I compute the
intersection of two arrays?
 
J

Jürgen Exner

Jim said:
Thanks, that appears to tell me the differences (although I'm n
ot quite sure what values it puts in what arrays, I'll have to
run it and find out). That's a slightly different problem than I
have - I want to know which elements of array2 ARE present in
array1.

Dude,

did you actually _read_ even just the full title of that FAQ?
Like the part that Anno marked with the ellipsis?

jue
 
J

Jim Weeb

Dude,

did you actually _read_ even just the full title of that FAQ?
Like the part that Anno marked with the ellipsis?

Yes, however the bit marked is about differences. After another
read I noticed the bit about intersection (and then it struck
what intersection meant).

Unfortunately after plumbing in that code it appears not to work
for me. Obviously a problem somewhere, perhaps I failed to
declare one of the variables (use strict) - do I have to declare
both %count and $count?

I will keep plodding along, then ask again if I can't make it
work.
 
A

A. Sinan Unur

....

....

Unfortunately after plumbing in that code it appears not to work
for me. Obviously a problem somewhere
Obviously.

I will keep plodding along, then ask again if I can't make it
work.

Or, as the guidelines suggest, you can post a short, self-contained
script that we can run, and which demonstrates the problem you are
having, so others can help you.

Sinan

PS: Why do you have X-No-Archive set?
 
J

Jürgen Exner

Jim said:
Yes, however the bit marked is about differences. After another
read I noticed the bit about intersection (and then it struck
what intersection meant).

My appologies. It wasn't clear from your reply that you did.
Unfortunately after plumbing in that code it appears not to work
for me.

Unfortunately "does not work" is completely useless as a description of what
is happening.
Obviously a problem somewhere, perhaps I failed to
declare one of the variables (use strict) - do I have to declare
both %count and $count?

The actual error message should tell you what is wrong.
If you don't understand the message then just post it here and ask.
Of course with the relevant snippet of the code.

Or rather post a minimal, self-contained sample script, that other people
can just copy and paste and run themself.

jue
 
J

Jim Weeb

Unfortunately after plumbing in that code it appears not to work
for me.

Unfortunately "does not work" is completely useless as a description of what
is happening.
Obviously a problem somewhere, perhaps I failed to
declare one of the variables (use strict) - do I have to declare
both %count and $count?

The actual error message should tell you what is wrong.
If you don't understand the message then just post it here and ask.
Of course with the relevant snippet of the code.[/QUOTE]

When I say I'm a complete newcomer, I really mean it. The code
runs on a debian box that is not attached to a keyboard/screen,
but I can SSH into it. The only reason I know that my
alterations to the code don't work is because the desired
outcome isn't achieved (the mail2news gateway bounces instead of
processes the email)! I wasn't quite sure where the error
message would be, never mind what it says, but I have gone on a
hunting spree and here it is (in Exim4's main log, as the script
is called as an Exim4 transport):

R=mail2news_router T=mail2news_transport: Child process of
mail2news_transport transport returned 255 (could mean shell
command ended by signal 127 (Unknown signal 127)) from command:
/usr/local/bin/mail2news.pl
Or rather post a minimal, self-contained sample script, that other people
can just copy and paste and run themself.

The entire script is quite small. If I remove anything from it I
might just bugger it up entirely.
 
R

robic0

Unfortunately "does not work" is completely useless as a description of what
is happening.


The actual error message should tell you what is wrong.
If you don't understand the message then just post it here and ask.
Of course with the relevant snippet of the code.

When I say I'm a complete newcomer, I really mean it. The code
runs on a debian box that is not attached to a keyboard/screen,
but I can SSH into it. The only reason I know that my
alterations to the code don't work is because the desired
outcome isn't achieved (the mail2news gateway bounces instead of
processes the email)! I wasn't quite sure where the error
message would be, never mind what it says, but I have gone on a
hunting spree and here it is (in Exim4's main log, as the script
is called as an Exim4 transport):

R=mail2news_router T=mail2news_transport: Child process of
mail2news_transport transport returned 255 (could mean shell
command ended by signal 127 (Unknown signal 127)) from command:
/usr/local/bin/mail2news.pl
Or rather post a minimal, self-contained sample script, that other people
can just copy and paste and run themself.

The entire script is quite small. If I remove anything from it I
might just bugger it up entirely.
[/QUOTE]

Jesus Christ, whats a nubian box? I hope its not what I think it is.
if it is I can programm that baby in 1 minute......
 
A

Anonymous

Or, as the guidelines suggest, you can post a short, self-contained
script that we can run, and which demonstrates the problem you are
having, so others can help you.

Yeah, if I have to ask again, it would involve me posting my
code.
PS: Why do you have X-No-Archive set?

Paranoia that Google are up to no good.
 
J

Jürgen Exner

Jim Weeb wrote:
[...]
processes the email)! I wasn't quite sure where the error
message would be, never mind what it says, but I have gone on a
hunting spree and here it is (in Exim4's main log, as the script
is called as an Exim4 transport):

R=mail2news_router T=mail2news_transport: Child process of
mail2news_transport transport returned 255 (could mean shell
command ended by signal 127 (Unknown signal 127)) from command:
/usr/local/bin/mail2news.pl

Well, this is certainly not a Perl error message.

jue
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,598
Members
45,151
Latest member
JaclynMarl
Top