Binding array to pattern

  • Thread starter Shmuel (Seymour J.) Metz
  • Start date
S

Shmuel (Seymour J.) Metz

on 06/16/2006 said:
These three lines are equivalent to
push @abuseContacts, @{$email_contact}
if grep /abuse/, $_, @{$email_contact};

Doesn't that have the problme you mention below?
You do realise this will push *all* of @{$email_contact} onto
@abuseContact, if *any* of them match?

Whoops! Thanks.

Perhaps

my $email_contact = $email_info->{$_} ;
push @Contacts, @$email_contact;
if (/abuse/) {
push @abuseContacts, @$email_contact;
} elsif (my @abuseSubset=grep /abuse/, @$email_contact) {
push @abuseContacts, @abuseSubset;
}
By 'abuse contacts' you mean 'email addresses matching /abuse/',
right?

I mean contacts designated for reporting abuse; looking for the string
"abuse" is just the best heuristic I could come up with.
[Side issue: are you sure you mean /abuse/ and not /^abuse\@/ ?]

Very :-(
...so you can read the tags and find the correct addr by hand?
Yes.

Do you want the whole whois reply, or just all the email addesses in
the reply?

The snippet of code in question is producing summary data; elsewhere I
do write out the full whois records.
Or have I misunderstood you?

There are some complications that you aren't aware of. There are cases
in my whois processing where I must recursively invoke whois;
$host_info{$host}{Email} may include contacts from multiple whois
records.
Err... not for a while :). Perl5 will be the supported and developed
version of Perl for the forseeable future. Some features of Perl6
are available for Perl5 in the modules in the Perl6::* namespace;
any() is in Perl6::Junction (or, as Uri said, in
Quantum::Superpositions, though that's likely much slower); also in
List::MoreUtils, which is probably what I'd use if I needed it.

I expect others to be using this program; I don't want to include
obsolete copies of code from CPAN, but I also don't want to require
them to download additional modules. So far I've been sticking with
modules that are included in the OS/2 distribution. Would it be better
form to not use additional modules, to use them and document a
download as part of the installation process or to supply potentially
obsolete copies with my program?

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to (e-mail address removed)
 
S

Shmuel (Seymour J.) Metz

on 06/16/2006 said:
again, you are somewhat unclear. 'put them in a message' means what?

A line or lines of text intended to be read by a human being.
'all of the email' means what?

Dropped word; I meant all of the e-mail addresses.
i smell an XY problem here. it is always best to explain the
original problem

Well, in this case the original problem would have only confused the
issue, since most of the code has nothing to do with the original
point of failure. In debugging I always try to generate a small test
case.
what is the format of the whois records?

Ad hoc. There are multiple conventions, and some seem to not follow
any conventions. The specific case that I'm trying to handle is where
there is a line of the form

role: e-mail-address

Since there is no standard for recognizing abuse contacts, I'm
applying the heuristic to treat it as abuse if the string "abuse"
appears either in the role name or in the address.

If you want I can send you the entire program, but it is very much a
work in progress and will ultimately need significant cleanup.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to (e-mail address removed)
 
S

Shmuel (Seymour J.) Metz

on 06/16/2006 said:
Using grep() in this situation *simplifies* the logic (and avoids the
potential bug).

Actually, both my code and yours have the same bug, pointed out by Mr.
Morrow.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to (e-mail address removed)
 
T

Tad McClellan

Shmuel (Seymour J.) Metz said:
Actually, both my code and yours have the same bug, pointed out by Mr.
Morrow.


What bug was that?

The bug of matching across element boundaries?
That is the only bug that I could see in Ben's post.

He used my code, and said that one of the reasons that it is
better than what you were doing was that it does NOT contain
that bug. Go read what he said again.

And it is the same bug that I had already pointed out anyway.


I provided code showing the bug in your approach, so you could believe me.

Please post code that shows a bug in my approach, so I can believe you.
 
B

Ben Morrow

Quoth "Shmuel (Seymour J.) Metz said:
Doesn't that have the problme you mention below?

Yes it does. Since I wasn't sure of what you wanted the code to do, I
left it doing the same as before.
Whoops! Thanks.

Perhaps

my $email_contact = $email_info->{$_} ;
push @Contacts, @$email_contact;
if (/abuse/) {
push @abuseContacts, @$email_contact;
} elsif (my @abuseSubset=grep /abuse/, @$email_contact) {
push @abuseContacts, @abuseSubset;
}

Given that @abuseSubset will be empty if there are no matches, I'd just
have

else {
push @abuseContacts, grep /abuse/, @$email_contact;
}

instead of that elsif.
I expect others to be using this program; I don't want to include
obsolete copies of code from CPAN, but I also don't want to require
them to download additional modules. So far I've been sticking with
modules that are included in the OS/2 distribution. Would it be better
form to not use additional modules, to use them and document a
download as part of the installation process or to supply potentially
obsolete copies with my program?

Well....... that's a tricky one. My instinct would be to put the whole
thing in a module, with little script installed as part of the module
installation, and then put it on CPAN with a proper dependancy list.
Then your instructions are of the form of 'install Net::WhoisAbuse from
CPAN' or whatever. Spamassassain is a good example of something that
works like this.

If for whatever reason (proprietary code, expected level of user not
familiar with CPAN...) you don't want to do this, then you can't really
tell the user to install stuff off CPAN unless you can write an install
script to do it for them. As far as bundling the module with your script
goes, since you seem to be working for one platform only it would
probably be easiest for your users to make a .exe (OS/2 does call them
..exe, right?) using PAR, assuming that's been ported to OS/2. Then they
don't need perl or anything.

If that's not possible, then I would still not give up on CPAN: it's the
whole point of writing Perl :). At the very least, you can gut a module
and put it in your own script:

use Foo::Bar qw/whatever/;

is equivalent to

BEGIN {
$INC{'Foo/Bar.pm'} = $0;
{
# contents of Foo/Bar.pm here
}
import Foo::Bar qw/whatever/;
}

as long as the module doesn't use XS, and as long as you don't declare
any my variables before that.

In this *particular* case, I don't think any() is worth the effort :).

Ben
 
S

Shmuel (Seymour J.) Metz

on 06/22/2006 said:
Given that @abuseSubset will be empty if there are no matches, I'd
just have
else {
push @abuseContacts, grep /abuse/, @$email_contact;
}
instead of that elsif.
Thanks.

since you seem to be working for one platform

It's my intent to support it for *ix as well as OS/2. Most of the
other users would not be on OS/2.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to (e-mail address removed)
 
S

Shmuel (Seymour J.) Metz

on 06/21/2006 said:
What bug was that?

The one that exists in the real world, not just in your imagination.
The bug of matching across element boundaries?

There is no "bug of matching across element boundaries" in the code,
only in your head. There was, however, a very real error that Mr.
Morrow pointed out in said:
That is the only bug that I could see in Ben's post.

Well, that tells me how carefully you read it.
Go read what he said again.

You mean "(though I suspect this isn't an issue in your case)."?
And it is the same bug that I had already pointed out anyway.

Yes, the same imaginary bug that you invented the first time.
I provided code showing the bug in your approach,

No you didn't. You provided code that had nothing to do with my
approach.
so you could believe me.

When someone makes the same bogus claim twice, I'm not likely to
believe him.
Please post code that shows a bug in my approach, so I can believe
you.

Why would you imagine that I care whether you believe me? From my
perspective Mr. Guttman and Mr. Morrow are far more important than
you. Their advice has certainly been more accurate, helpful and
relevant.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to (e-mail address removed)
 
T

Tad McClellan

Shmuel (Seymour J.) Metz said:
The one that exists in the real world, not just in your imagination.


We did not know the "real world" when I pointed out that bug
because you didn't give a complete enough specification.

At that point all we had was /pattern/, so we did not know that
your pattern did not contain spaces.

There is no "bug of matching across element boundaries" in the code,


There is if there is a space in /pattern/

You mean "(though I suspect this isn't an issue in your case)."?


Because by then you had revealed what "your case" was. That had
not yet been revealed when I pointed out a bug. I cannot see
the future.

Yes, the same imaginary bug that you invented the first time.


It was not imaginary, it was entirely possible with the information
that was available at the time I wrote it.

No you didn't. You provided code that had nothing to do with my
approach.


Your approach was to concatenate all of the elements together,
and add a space character between each element.

The code I provided to demonstrate the bug used that same approach.
 
S

Shmuel (Seymour J.) Metz

on 06/22/2006 said:
We did not know the "real world" when I pointed out that bug

When you don't know the real world then your have no way of knowing
whether a bug is possible. Further, you kept nattering about the
imaginary bug *after* you had seen the code.

No, there is a potential bug that it might have made sense to ask
about; my code might fail if you set $" to a null string.
There is if there is a space in /pattern/

If your grandmother had wheels she'd be a wagon. You kept on referring
to your imaginary bug *after* you had seen that there was no space in
the /abuse/ pattern.
Because by then you had revealed what "your case" was. That had not
yet been revealed when I pointed out a bug. I cannot see the future.

You also cannot see the past. You seem to be careless in your reading
of news articles and to be appallingly ignorant of languages other
than Perl. There isn't a SNOBOL's chance in Hell that I would take
your unsupported word on anything.
It was not imaginary, it was entirely possible with the information
that was available at the time I wrote it.

Not the second time you wrote it.
Your approach was to concatenate all of the elements together, and
add a space character between each element.

No, my approach was to add $" between elements.

--
Shmuel (Seymour J.) Metz, SysProg and JOAT <http://patriot.net/~shmuel>

Unsolicited bulk E-mail subject to legal action. I reserve the
right to publicly post or ridicule any abusive E-mail. Reply to
domain Patriot dot net user shmuel+news to contact me. Do not
reply to (e-mail address removed)
 

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

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top