[31647] in Perl-Users-Digest
Perl-Users Digest, Issue: 2910 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Apr 13 21:09:26 2010
Date: Tue, 13 Apr 2010 18:09:07 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Tue, 13 Apr 2010 Volume: 11 Number: 2910
Today's topics:
Re: Matchtable sln@netherlands.com
Re: Net::SMTP errors (Seymour J.)
Re: Question about Algorithm::Diff <nospam-abuse@ilyaz.org>
Re: Question about Algorithm::Diff <ednotover@gmail.com>
software requirements again, retrospective <cartercc@gmail.com>
Re: software requirements again, retrospective <bmb@mail.libs.uga.edu>
Re: software requirements again, retrospective <ben@morrow.me.uk>
Re: software requirements again, retrospective <cartercc@gmail.com>
Re: software requirements again, take 483 <RedGrittyBrick@SpamWeary.invalid>
Re: software requirements again, take 483 <jurgenex@hotmail.com>
Using new features of Perl <sigzero@gmail.com>
Re: Using new features of Perl <ben@morrow.me.uk>
Re: Using new features of Perl <sigzero@gmail.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 13 Apr 2010 11:02:56 -0700
From: sln@netherlands.com
Subject: Re: Matchtable
Message-Id: <4d69s5tr10la7o7alcm9d0cgedv12lcuug@4ax.com>
On Tue, 13 Apr 2010 10:00:50 +0200, Bernard <boerni_s@bluewin.ch> wrote:
>Hi all
>
>Thank you very much for your responses.
>
>I found a solution that works for me in the meantime.
>Bernard
>
>Table looks like this:
>#Hostname| Subsystem | Probe | User Tag | Group
>* | System* | nt* | * | NT_Group
>asdf* | System* | nt* | * | NT_Group_APAC
>us* | pr* | Misc* | * | US_Servicedesk
>us-* | * | * | * | US_Network
>* | * | * | * | Default_Group
>
>Script:
>#!perl -w
>use strict;
>
>my $table_file = './io/matchtst.lst';
>
>my $table = read_table($table_file) or die;
>
>my $group = find_match( $table,
> 'us-asdf',
> 'printer',
> 'Domino',
> '') or die;
>
>print "Group is $group\n";
>exit 0;
>
>
>#---- Subroutinen ----#
>
>sub read_table {
> my $table_file = shift;
>
> my $table;
> open(IN, $table_file) or die "cant read $table_file: $!\n";
open(IN, '<', $table_file) or ...
>
> while(<IN>) {
> chomp;
> next if (/^\#/ or ! $_);
>
> s/\*/\.\*/g;
my $line;
while( defined($line = <IN>) ) {
chomp $line;
next if ($line =~ /^\#/ || $line =~ /^\s*$);
$line =~ s/\*/\.\*/g; # .* precludes any other quantifiers following
# It basically means there can be only one '*' (.*)
# per line as it's length is given 'weight'
>
> my ($field1, $field2, $field3, $field4, $output) = split(/\s+\|\s+/);
>
# validate fields are defined
if (!(defined($field1) &&
defined($field2) &&
defined($field3) &&
defined($field4) &&
defined($output)) ) {
print "Table record is undefined", $line, "\n";
next;
}
> my $key = join('~~', ($field1, $field2, $field3, $field4));
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
# validate it is not a duplicate key (leading to a possible different $output field)
if (!exists( $table->{$key} ) ) {
> $table->{$key}->{'field1'} = $field1;
> $table->{$key}->{'field2'} = $field2;
> $table->{$key}->{'field3'} = $field3;
> $table->{$key}->{'field4'} = $field4;
> $table->{$key}->{'output'} = $output;
}
else {
print "Duplicate key found: ", $table->{$key}, "\n"
}
> }
>
> close IN;
>
> return $table;
>}
>
>sub find_match {
> my %fields;
> my %score;
>
> my $table = shift;
>
> my $field1 = shift;
> my $field2 = shift;
> my $field3 = shift;
> my $field4 = shift;
>
$score{'score'} = 0;
> foreach my $key(sort {length($b) <=> length($a)} keys %$table) {
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Here, if you are sorting by the length of the key in descending order,
there is no need to stay in the loop once you have found a match
>
> if ($field1 =~ /$table->{$key}->{'field1'}/ and
^^ use && instead
> $field2 =~ /$table->{$key}->{'field2'}/ and
> $field3 =~ /$table->{$key}->{'field3'}/ and
> $field4 =~ /$table->{$key}->{'field4'}/) {
>
> if (! $score{'score'} or ($score{'score'} < length($key))) {
^^ use || instead
^^^^^^^^^^
no need to keep checking for this
if ( $score{'score'} < length($key) ) {
> $score{'score'} = length($key);
> $score{'pattern'} = $key;
> }
> }
> }
>
> return $table->{$score{'pattern'}}->{'output'};
^^^^^^^^^^^^^ I don't know if it was found
if (exists $score{'pattern'} ) {
return $table->{$score{'pattern'}}->{'output'};
}
return "Cannot find $score{'pattern'} !";
>
>}
I wasn't sure if you were actually going to use this table
as regexp's for search. Now I see you are.
While it is ok to have a table of regexp's, you have
totally crippled it by weighting it on the length of the
joined fields regexp's ie: us*~~pr*~~Misc*~~*
The fact is, it is possible to have different lengths
where the shorter length is the most significant, thats
the only argument needed against that approach. It then
becomes non-systematic, un-programmable.
Its limited regex. You can only have one '*' and at the end only
and I think thats it.
This will force you into making multiple line items per group,
and eventually having to add attribute's for distinction.
IMO, its better to weight the fields based on significance (say, from
left to right) instead of depending upon the combined length of the
fields.
Good job.
-sln
------------------------------
Date: Tue, 13 Apr 2010 07:46:39 -0400
From: Shmuel (Seymour J.) Metz <spamtrap@library.lspace.org.invalid>
Subject: Re: Net::SMTP errors
Message-Id: <4bc4599f$11$fuzhry+tra$mr2ice@news.patriot.net>
In <45022a07-aed7-4312-beca-aaab40fecf9b@12g2000yqi.googlegroups.com>, on
04/12/2010
at 11:31 AM, "david.karr" <davidmichaelkarr@gmail.com> said:
> $smtp->mail($ENV{USER});
From RFC 5321:
Mailbox = Local-part "@" ( Domain / address-literal )
>Net::SMTP=GLOB(0x10b822c0)<<< 553 5.5.4 <<myid>>... Domain name required
>for sender address <myid>
See above.
>Net::SMTP=GLOB(0x10b822c0)>>> RCPT TO:<<myid>@<mydomain>>
That looks like a bug; it should have sent a QUIT after the 553 on the
MAIL command.
--
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 spamtrap@library.lspace.org
------------------------------
Date: Tue, 13 Apr 2010 11:01:06 +0000 (UTC)
From: Ilya Zakharevich <nospam-abuse@ilyaz.org>
Subject: Re: Question about Algorithm::Diff
Message-Id: <slrnhs8jni.nlr.nospam-abuse@powdermilk.math.berkeley.edu>
On 2010-04-13, Kyle T. Jones <KBfoMe@realdomain.net> wrote:
>> Solution 1:
>> ---ab
>> a1bab
>>
>
>
> [
> ['+', 0, 'a'],
> ['+', 1, '1'],
> ['+', 2, 'b'],
> ]
>
>> Solution 2:
>> a-b--
>> a1bab
>>
>
>
> [
> ['+', 1, '1'],
> ['+', 3, 'a'],
> ['+', 4, 'b'],
> ]
>
>> Solution 3:
>> a---b
>> a1bab
>>
>
>
> [
> ['+', 1, '1'],
> ['+', 2, 'b'],
> ['+', 3, 'a'],
> ]
> Why are any of the three better?
Obviously, the metric the OP wants is: assign the "identity edit"
weight eps, and any other edit weight 1+eps, with the exception that N
consecutive edits of the same type get weight N+eps, not N + N*eps.
Looks reasonable (if one convert it to a cheap algorithm to find the
best match...).
Hope this helps,
Ilya
------------------------------
Date: Tue, 13 Apr 2010 07:48:08 -0700 (PDT)
From: Ed <ednotover@gmail.com>
Subject: Re: Question about Algorithm::Diff
Message-Id: <4566c279-2dce-42fd-a83e-942303a6a7fb@e7g2000yqf.googlegroups.com>
On Apr 12, 4:24=A0pm, Dilbert <dilbert1...@gmail.com> wrote:
> Theoretically there are 3 solutions with LCS =3D 2:
>
> Solution 1:
> ---ab
> a1bab
>
> Solution 2:
> a-b--
> a1bab
>
> Solution 3:
> a---b
> a1bab
>
> I understand that any of those 3 solutions could be returned by
> Algorithm::Diff, but I would argue that solution 1 is "better" than
> solution 2 or 3, because solution 1 changes only once between '-' and
> [ab], whereas solution 2 and 3 change more than once between '-' and
> [ab].
> my $d =3D Algorithm::Diff::sdiff(\@old, \@new);
> How can I teach Algorithm::Diff to choose Solution 1 (the best of the
> 3 possibilities) ?
Look at traverse_balanced as a starting point. Basically you'd need
to write your own diff calculator based off the LCS, using whatever
method you feel is appropriate. Once you get to the point where
you're looking for the "best" of the possible solutions, you are in
new territory since you'll have to consider the solution set. I don't
think there's anything in Algorithm::Diff that does that sort of thing
- I believe the code simply finds the first solution that uses the
given LCS.
------------------------------
Date: Tue, 13 Apr 2010 08:46:04 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: software requirements again, retrospective
Message-Id: <c021b160-5de2-4d04-bdaa-73a42c3a3911@30g2000yqi.googlegroups.com>
This isn't a complaint, gripe, or an appeal to sympathy. It's simply a
report on a conversation I had yesterday. You can draw your own
conclusions.
In case you missed the first installment, I vented on c.l.p.m. because
of a series of 'unknown' requirements that I had to implement after
the fact. The project was preparing a series of task documents
detailing specific tasks for several hundred people. The software was
already a week late when I discovered a major requirement that no one
had previously specified.
The project wasn't owned by IT, but by the business side with the
parameters and template dictated by HR. My role was to do what I was
told to do. I had no input into the requirements, design, or work
schedule.
Anyway, the conversation I had yesterday was with a friend of mine,
one of my upstream contacts, with a long time business background who
had been an IT manager for about three years. What he said was this:
"When you find out about a project, you start immediately. Don't wait
for people to tell you what to do, you start writing the code at once.
When you get the details, you can change what you have written."
The purpose of this conversation was to discuss a to-do list of about
six items that we know have to change, and a promise of a number of
other changes that we will get in several weeks. I said that I would
wait until I saw all the changes before I started on the updated
version. My friend said: "No, start making the changes now, and you
will be that far ahead."
Here's the point -- The business managers have a mind set that you can
get a head start on a project by building it before you know what it
is. Once you get word of it, you start on it. That way, when the boss
mentions it, you can say, "We've already started and it's underway."
That's what happened to me, with no knowledge that I was being fed
requirements piecemeal, with no thought as to how the tasks would be
specified. (Yes, I was stupid.)
I don't know what the lesson of this is, except that you do your job,
if you're lucky enough to have one, and do the best you can with what
you have, not expecting to change the culture of the business side.
Thanks, CC.
------------------------------
Date: Tue, 13 Apr 2010 12:37:16 -0400
From: Brad Baxter <bmb@mail.libs.uga.edu>
Subject: Re: software requirements again, retrospective
Message-Id: <hq26js$2f0m$1@news.telesweet.net>
On 4/13/2010 11:46 AM, ccc31807 wrote:
> Here's the point -- The business managers have a mind set that you can
> get a head start on a project by building it before you know what it
> is. Once you get word of it, you start on it. That way, when the boss
> mentions it, you can say, "We've already started and it's underway."
> That's what happened to me, with no knowledge that I was being fed
> requirements piecemeal, with no thought as to how the tasks would be
> specified. (Yes, I was stupid.)
Makes me think of
http://en.wikipedia.org/wiki/Agile_software_development#Principles
My experience is that your experience will likely be all over the map.
:-)
My philosophy: You can't steer a canoe that isn't moving. But I
also have no illusions that I'm particularly competent at project
management. I'm okay with that.
--
Brad
------------------------------
Date: Tue, 13 Apr 2010 18:40:17 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: software requirements again, retrospective
Message-Id: <1tme97-01q.ln1@osiris.mauzo.dyndns.org>
Quoth ccc31807 <cartercc@gmail.com>:
> This isn't a complaint, gripe, or an appeal to sympathy. It's simply a
> report on a conversation I had yesterday. You can draw your own
> conclusions.
<snip>
WTF does any of this have to do with Perl?
clpmisc is not the place for these rants. LiveJournal is -->thataway.
Ben
------------------------------
Date: Tue, 13 Apr 2010 14:03:07 -0700 (PDT)
From: ccc31807 <cartercc@gmail.com>
Subject: Re: software requirements again, retrospective
Message-Id: <6ecc010b-db9d-4c40-8ffd-7980fa41ae7c@x12g2000yqx.googlegroups.com>
On Apr 13, 1:40=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> WTF does any of this have to do with Perl?
Has the same relevance to Perl as analysis and design has to
implementation. Why is as much a part of the discussion as What.
> clpmisc is not the place for these rants. LiveJournal is -->thataway.
Unfortunately, we write in the real world, interacting with real users
with real needs, dealing with real problems. Reality is often messy.
I'm sorry if it offends you, but you always have the option of not
reading these kinds of threads -- and it's not as if I snookered you
into reading it by false pretenses, I clearly titled the thread in
such a way that you would know the subject.
Kinda reminds me of the tom peeper who blamed his activities on the
women undressing in their bedrooms. ;-)
CC.
------------------------------
Date: Tue, 13 Apr 2010 19:45:40 +0100
From: RedGrittyBrick <RedGrittyBrick@SpamWeary.invalid>
Subject: Re: software requirements again, take 483
Message-Id: <IuSdnWl-sYZIJlnWnZ2dnUVZ8lednZ2d@bt.com>
On 12/04/2010 21:26, David Formosa (aka ? the Platypus) wrote:
> On Mon, 05 Apr 2010 15:44:04 -0700, Jürgen Exner<jurgenex@hotmail.com> wrote:
> [...]
>> And I cannot imagine how email or the Internet or Usenet would work
>> without any written specs and protocols.
>
> Usenet and email both where cases where existing protocols where
> documented after they where implimented rather then the other way
> around.
I believe Jürgen's point is that the specification for those protocols
was agreed on and written down. Subsequent developers of e-mail software
have benefited enormously from this. As have users.
Contrast this with proprietary email systems such as cc:Mail where there
were few, if any, directly interoperable implementations from other
vendors. I remember the era before corporations adopted Intenet mail
standards - it was a mess of complex expensive e-mail gateways.
Contrast also with OSI X.400 where you had to pay to see the standards
and where the standards specified huge numbers of options to satisfy
various vendors, with the outcome that few implementations implemented
all the options and consequently interoperability was limited.
As I understand it, the IETF standards process always required several
working implementations of a protocol before the draft standard could be
ratified. The RFCs were, and are, a vitally important part of the
Internet's success.
--
RGB
------------------------------
Date: Tue, 13 Apr 2010 12:01:41 -0700
From: Jürgen Exner <jurgenex@hotmail.com>
Subject: Re: software requirements again, take 483
Message-Id: <knf9s5te7p5i8c1402bqm7va02fhjhtt0c@4ax.com>
"David Formosa (aka ? the Platypus)" <dformosa@usyd.edu.au> wrote:
>On Mon, 05 Apr 2010 15:44:04 -0700, Jürgen Exner <jurgenex@hotmail.com> wrote:
>[...]
>> And I cannot imagine how email or the Internet or Usenet would work
>> without any written specs and protocols.
>
>Usenet and email both where cases where existing protocols where
>documented after they where implimented rather then the other way
>around.
If today you were given the task of implementing a new email server from
scratch, would you rather reverse engineer the protocols by observing
the data flow in an existing system or would you consult the written
RFCs?
jue
------------------------------
Date: Tue, 13 Apr 2010 11:51:52 -0700 (PDT)
From: Robert Hicks <sigzero@gmail.com>
Subject: Using new features of Perl
Message-Id: <dd0178a3-52ee-451a-8360-d2ae129b9431@n3g2000vbl.googlegroups.com>
This is just a "like to know" question.
Does:
use feature "switch";
incur anything more or less than:
use feature ":5.10"; # which gives you switch and everything
else
Is it good practice just to pull in what you want with the first one?
Bob
------------------------------
Date: Tue, 13 Apr 2010 20:56:15 +0100
From: Ben Morrow <ben@morrow.me.uk>
Subject: Re: Using new features of Perl
Message-Id: <vrue97-ctq.ln1@osiris.mauzo.dyndns.org>
Quoth Robert Hicks <sigzero@gmail.com>:
> This is just a "like to know" question.
>
> Does:
>
> use feature "switch";
>
> incur anything more or less than:
>
> use feature ":5.10"; # which gives you switch and everything
> else
Well, yes.
use feature ":5.10";
is equivalent to
use feature qw/switch say state/;
so you get 'say' and 'state' keywords as well as 'given' and 'when'.
> Is it good practice just to pull in what you want with the first one?
IMHO best practice would be
use 5.010;
at the top of any file using these features, but note the 'would be'
rather than 'is' since 'feature' as a whole is fairly new and it's not
necessarily clear yet if there are any significant gotchas.
Ben
------------------------------
Date: Tue, 13 Apr 2010 15:39:05 -0700 (PDT)
From: Robert Hicks <sigzero@gmail.com>
Subject: Re: Using new features of Perl
Message-Id: <4ae1431e-7d02-47d6-9c33-262e22eb2eb5@z4g2000yqa.googlegroups.com>
On Apr 13, 3:56=A0pm, Ben Morrow <b...@morrow.me.uk> wrote:
> Quoth Robert Hicks <sigz...@gmail.com>:
>
> > This is just a "like to know" question.
>
> > Does:
>
> > =A0 =A0 use feature "switch";
>
> > incur anything more or less than:
>
> > =A0 =A0 use feature ":5.10"; =A0 # which gives you switch and everythin=
g
> > else
>
> Well, yes.
>
> =A0 =A0 use feature ":5.10";
>
> is equivalent to
>
> =A0 =A0 use feature qw/switch say state/;
>
> so you get 'say' and 'state' keywords as well as 'given' and 'when'.
>
> > Is it good practice just to pull in what you want with the first one?
>
> IMHO best practice would be
>
> =A0 =A0 use 5.010;
>
> at the top of any file using these features, but note the 'would be'
> rather than 'is' since 'feature' as a whole is fairly new and it's not
> necessarily clear yet if there are any significant gotchas.
>
> Ben
Thanks for your answer Ben.
Bob
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 2910
***************************************