[23999] in Perl-Users-Digest
Perl-Users Digest, Issue: 6200 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Mar 1 18:10:44 2004
Date: Mon, 1 Mar 2004 15:10:11 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 1 Mar 2004 Volume: 10 Number: 6200
Today's topics:
Re: OS Version <Joe.Smith@inwap.com>
perl implementation of rand() and srand() <simschla@freesurf.ch>
Re: perl implementation of rand() and srand() <ittyspam@yahoo.com>
Re: perl implementation of rand() and srand() <simschla@freesurf.ch>
Re: Regex comparison <tadmc@augustmail.com>
Re: Regex comparison <noreply@gunnar.cc>
Re: Regex comparison <usenet@morrow.me.uk>
Re: Regex comparison <lpeters@aol.net>
Re: Regex comparison (Malcolm Dew-Jones)
Sexy code? (Miko O'Sullivan)
Re: split into array <g_klinedinst@hotmail.com>
Re: split into array <gnari@simnet.is>
Re: split into array <g_klinedinst@hotmail.com>
Re: Storing numbers in an array from files <Joe.Smith@inwap.com>
Re: Suggest a suitable image modifying CPAN module <gnari@simnet.is>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 01 Mar 2004 20:48:01 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: OS Version
Message-Id: <5kN0c.156683$jk2.597191@attbi_s53>
Mark J Fenbers wrote:
> Well, because I have third-party software that I call from my script and that
> software has to be called with different environmental settings on RH 9 than it does
> for RH 7.
Why? If it is because one distribution as files in a particular
directory and the other does not, then test for the existence of
that directory.
Testing the OS (the version of the kernel) won't help.
$os = `uname -r`;
if ($os =~ /^2.4.20-28.\d+$/) {
print "Kernel version indicates patched RH7.1 or patched RH9\n";
}
-Joe
------------------------------
Date: Mon, 1 Mar 2004 22:46:55 +0100
From: Simon <simschla@freesurf.ch>
Subject: perl implementation of rand() and srand()
Message-Id: <fx44ums7a05f.vwliyfnyhwhe$.dlg@40tude.net>
hi everyone
I'm trying to implement a Java-version of the perl-based "razor"-client.
razor is spamfilter using a client-server system where users can "vote" if
a message is spam or not. (it is commercially known under the name
"spamnet").
The client is able to choose random positions in a e-mail-message and
computes these parts of the message to build an identifier (hash).
The positions are chosen according to the following system:
srand(<server specified seed-number>);
rand(<length of message>); several times to chose portions of the text.
all clients and all servers have to use the same positions in order to
generate a comparable identifier for the message. This is my problem: if I
want to implement a Java-Client for this system, i have to be able to
generate the same "random" number sequence in Java. I need the source code
of the perl implementation of srand() and rand() to be able to do this. can
anyone point me in the right direction please?
thx
Simon
------------------------------
Date: Mon, 1 Mar 2004 16:58:16 -0500
From: Paul Lalli <ittyspam@yahoo.com>
Subject: Re: perl implementation of rand() and srand()
Message-Id: <20040301165733.V27834@dishwasher.cs.rpi.edu>
On Mon, 1 Mar 2004, Simon wrote:
> generate a comparable identifier for the message. This is my problem: if I
> want to implement a Java-Client for this system, i have to be able to
> generate the same "random" number sequence in Java. I need the source code
> of the perl implementation of srand() and rand() to be able to do this. can
> anyone point me in the right direction please?
>
The right direction for the source code to perl? Here:
http://www.cpan.org/src/
Paul Lalli
------------------------------
Date: Mon, 1 Mar 2004 23:03:12 +0100
From: Simon <simschla@freesurf.ch>
Subject: Re: perl implementation of rand() and srand()
Message-Id: <sp1rm0fzek1t$.uvuyl1pszrg9.dlg@40tude.net>
On Mon, 1 Mar 2004 16:58:16 -0500, Paul Lalli wrote:
> The right direction for the source code to perl? Here:
> http://www.cpan.org/src/
i've managed to find that link, too, but wasn't able to find anything about
the implementation of srand() or rand() inside it. if it's in there, can
someone tell me where to look for it?
Simon
------------------------------
Date: Mon, 1 Mar 2004 14:52:24 -0600
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: Regex comparison
Message-Id: <slrnc478k8.kr5.tadmc@magna.augustmail.com>
Les Peters <lpeters@aol.net> wrote:
> Trying to
> take pattern-1 and transform it into a string,
so for /a+/, you need to expand it to:
a
aa
aaa
aaaa
aaaaa
aaaaaa
aaaaaaa
aaaaaaaa
...
Let us know when you get that one finished. :-)
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 01 Mar 2004 21:58:38 +0100
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Regex comparison
Message-Id: <c208ih$1nrmm6$1@ID-184292.news.uni-berlin.de>
Les Peters wrote:
>
> sub pattern_check {
> #my ($p1, $p2) = @_;
> my ($p1) = @_;
>
> # transform p1 into s1 that matches p1
>
> my $s1;
> $s1 = $p1;
> print "I $p1\n";
> $s1 =~ s/\\d[\+\*]?/0/g; # replace \d, \d+, \d*
> $s1 =~ s/\\s[\+\*]?/ /g; # replace \s, \s+, \s*
> $s1 =~ s/\\S[\+\*]?/-/g; # replace \S, \S+, \S*
> $s1 =~ s/\.[\+\*]/-/g; # replace .+, .*
> $s1 =~ s/\\\+/+/g; # replace \+
> while ($s1 =~ /([^\\])\[(.)[^]]*?\]/) {
> $s1 =~ s/([^\\])\[(.)[^]]*?\]/\1\2/; # replace character range
> }
> $s1 =~ s/\\\[(.)[^]]*?\\\]/\[\1\]/g; # replace bracketed character
> range
>
> $s1 =~ s/\((.+?)\|.+?\)/\1/g; # replace alternation
> $s1 =~ s/([^\\])[()]/\1/g;
> $s1 =~ s/\\([\[\]\(\)\/\.'"])/\1/g; # replace backslashed []()/.'"
>
> print "O $s1\n";
> if ($s1 =~ /$p1/) {
> print "match\n";
> } else {
> print "NO\n";
> }
> print "\n";
>
> # attempt to match s1 with p2
> # if successful, conflict
>
> }
Wow, you were really working. :)
Even if I'm afraid that this is somewhat above my head (not the first
time in this group), I do have a feeling that what you are trying to
do - kind of reversing the regex engine - would result in anything but
robust code.
> I am trying to properly order a series of regexen so that a general
> pattern will not match all the lines of a more specific pattern, as
> part of a log monitoring script.
Please consider this approach:
my $string = 'abc123###def456ghi789###jkl012mno';
my $genre = qr/\w+/;
my $subre = qr/\d+/;
my (@genmatches, @submatches);
while ($string =~ /($genre)/g) {
my $part = $1;
push @submatches, $part =~ /($subre)/g;
push @genmatches, split /$subre/, $part;
}
print "@genmatches\n";
print "@submatches\n";
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 1 Mar 2004 21:10:12 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: Regex comparison
Message-Id: <c208rk$b7l$1@wisteria.csv.warwick.ac.uk>
Les Peters <lpeters@aol.net> wrote:
> I am trying to properly order a series of regexen so that a general pattern
> will not match all the lines of a more specific pattern, as part of a log
> monitoring script.
This problem is not well-defined: which is the more specific of these
/[abc]/ and /[cd]/
?
Ben
--
And if you wanna make sense / Whatcha looking at me for? (Fiona Apple)
* ben@morrow.me.uk *
------------------------------
Date: Mon, 01 Mar 2004 16:30:24 -0500
From: Les Peters <lpeters@aol.net>
Subject: Re: Regex comparison
Message-Id: <4043AB70.6030208@aol.net>
Ben Morrow wrote:
> Les Peters <lpeters@aol.net> wrote:
>
>>I am trying to properly order a series of regexen so that a general pattern
>>will not match all the lines of a more specific pattern, as part of a log
>>monitoring script.
>
>
> This problem is not well-defined: which is the more specific of these
>
> /[abc]/ and /[cd]/
Those two patterns would have equal specificity.
The problem lies with patterns like:
/abc/ and /abcde/
if /abc/ is reached first, it will match the lines that /abcde/ would match,
therefore, /abcde/ should be used first, then /abc/.
Here is an update to the routine (I will be collapsing some of
this after it works for a significantly complex problem set):
sub pattern_check {
#my ($p1, $p2) = @_;
my ($p1) = @_;
# transform p1 into s1 that matches p1
my $s1;
$s1 = $p1;
$s1 =~ s/^\^//; # replace ^
if ($s1 =~ /\\d{(\d+)}/) {
my $patch = "0" x $1;
$s1 =~ s/\\d{(\d+)}/$patch/g;
}
$s1 =~ s/\\d[\+\*]?/0/g; # replace \d, \d+, \d*
$s1 =~ s/\\D[\+\*]?/-/g; # replace \D, \D+, \D*
$s1 =~ s/\\s[\+\*]?/ /g; # replace \s, \s+, \s*
$s1 =~ s/\\S[\+\*]?/-/g; # replace \S, \S+, \S*
$s1 =~ s/\\w[\+\*]?/a/g; # replace \w, \w+, \w*
$s1 =~ s/\\W[\+\*]?/-/g; # replace \W, \W+, \W*
$s1 =~ s/([^\\])\+/\1/g; # replace <non-backslash>+
$s1 =~ s/([^\\])\*//g; # replace <non-backslash>+
$s1 =~ s/\\\+/+/g; # replace \+
$s1 =~ s/\\\$/\$/g; # replace \$
$s1 =~ s/\\\*/*/g; # replace \*
$s1 =~ s/\\\././g; # replace \.
$s1 =~ s/\\</</g; # replace \<
$s1 =~ s/\\>/>/g; # replace \>
$s1 =~ s/ +[\+\*]/ /g; # replace <space>+, <space>*
while ($s1 =~ /([^\\])\[(.)[^]]*?\][\+\*]?/) {
$s1 =~ s/([^\\])\[(.)[^]]*?\][\+\*]?/\1\2/; # replace character range
}
if ($s1 =~ /[^\\]\|/) {
($begin, $end) = split(/\|/,$s1);
@chars = split(//,$begin);
$sparen_count = scalar grep(/\(/,@chars);
$eparen_count = scalar grep(/\)/,@chars);
if ((($sparen_count - $eparen_count) % 2) == 0) {
$s1 = $begin;
}
}
while ($s1 =~ /\((.+?)\|.+?\)/) {
$s1 =~ s/\((.+?)\|.+?\)/\1/g; # replace alternation
}
while ($s1 =~ /(.+?)\|.+?/) {
$s1 =~ s/(.+?)\|.+?/\1/g; # replace alternation
}
$s1 =~ s/([^\\])[()]/\1/g;
$s1 =~ s/\\([\-\[\]\(\)\/\.'"?@#{}])/\1/g; # replace backslashed -[]()/.'"?@#{}
$s1 =~ s/\$$//; # replace $
if ($s1 !~ /$p1/) {
print "I /$p1/\n";
print "O '$s1'\n";
print "NO\n";
print "\n";
}
# attempt to match s1 with p2
# if successful, conflict
}
At the moment, the code is tripping over this pattern:
/login\[[\d]+\]: failed: ^C on /dev/ttyd\d|login\[[\d]+\]: failed: on /dev/ttyd\d|login\[[\d]+\]: Locked ^C account|login\[[\d]+\]:
Locked account/
Specifically, the first caret is giving it fits.
Les
------------------------------
Date: 1 Mar 2004 14:55:56 -0800
From: yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones)
Subject: Re: Regex comparison
Message-Id: <4043bf7c@news.victoria.tc.ca>
Les Peters (lpeters@aol.net) wrote:
: Hey:
: I am working on a bit of code that will compare two regexen
: to see if one will match a superset of the other. Trying to
: take pattern-1 and transform it into a string, then try to match
: it against pattern-2 is getting really hard... any better methods?
You build the directed graph that represents the first regular expression,
and then you build the directed graph that represents the second regular
expression.
Then you check if one graph is a subset of the other.
However, I have no suggestion on the perl code to do this, though it
sounds like an interesting problem.
--
Web Work Wanted, Perl Projects Programmed, Database Development Done.
I'm looking for telecommute projects. (Paying that is, various
arrangements possible.)
------------------------------
Date: 1 Mar 2004 13:41:40 -0800
From: miko@idocs.com (Miko O'Sullivan)
Subject: Sexy code?
Message-Id: <db27ea77.0403011341.bb66c9@posting.google.com>
So there I am, reading some online Perl documentation. My wife
Starflower walks into my office and looks over my shoulder. She gets a
quizzical expression on her face and says "sexy code"?
"Huh?", I say, no clue what she's talking about.
"Right there," she points, "'sexy code'".
I look at the screen. All I see is a bunch of technical documentation.
Interesting stuff to me, but not something that most people would call
sexy. "I don't see anything sexy. What are you talking about?" I say.
"Right THERE", she says, and puts her finger right under a word:
$exitcode
Interesting how a paradigm shift can really change the meaning of
things.
------------------------------
Date: Mon, 01 Mar 2004 11:08:41 -0800
From: Greg Klinedinst <g_klinedinst@hotmail.com>
Subject: Re: split into array
Message-Id: <f12740hdndg89r970ass1hqd1o76fqdpc5@4ax.com>
On Mon, 01 Mar 2004 16:09:58 +0100, Gunnar Hjalmarsson
<noreply@gunnar.cc> wrote:
>Hmm.. Is it just me who don't find that to be the height of clearness?
>I rather find it to border on an 'undisclosed feature'. :(
I was following along with this thread and I agree with you. The docs
aren't quite clear.
I can deduce that this:
@myarray = split /,/, $myline, 1000;
would work too, since a negative is treated as a arbitrarily large
positive. Of course the -1 option looks much nicer, and is usable
universally.
A better way to write the sentence in question might be:
"If LIMIT is specified and positive, splits into a maximum of that
many fields or the number of total fields including null fields,
whichever is lower."
-Greg
------------------------------
Date: Mon, 1 Mar 2004 19:51:06 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: split into array
Message-Id: <c2045e$f9l$1@news.simnet.is>
"Greg Klinedinst" <g_klinedinst@hotmail.com> wrote in message
news:f12740hdndg89r970ass1hqd1o76fqdpc5@4ax.com...
[snip discussion about the clearness of perldoc -f split]
>
> A better way to write the sentence in question might be:
>
> "If LIMIT is specified and positive, splits into a maximum of that
> many fields or the number of total fields including null fields,
> whichever is lower."
I do not agree. I think the docs are quite clear, and your version
is more confusing. the split() function is amazingly complicated,
with lots of special cases. the docs do an admirable job of
describing each effect separately in a clear way.
gnari
------------------------------
Date: Mon, 01 Mar 2004 13:07:09 -0800
From: Greg Klinedinst <g_klinedinst@hotmail.com>
Subject: Re: split into array
Message-Id: <dq77405u9m7rh658ebhru3dvieq2neqp7r@4ax.com>
On Mon, 1 Mar 2004 19:51:06 -0000, "gnari" <gnari@simnet.is> wrote:
>I do not agree. I think the docs are quite clear, and your version
>is more confusing. the split() function is amazingly complicated,
>with lots of special cases. the docs do an admirable job of
>describing each effect separately in a clear way.
Hmm, perhaps I wasn't clear myself, or at least I used the wrong word.
The clarity is fine, what is lacking is the completeness. For example
it is clear that if LIMIT is unspecified or null split will strip null
fields. However logically we cannot assume that if LIMIT is specified
the opposite will happen. The only two other relevant statements say
that we can set a maximum using a positive integer(though it may split
into fewer, but how many is "fewer" referring to?), and that a
negative integer acts as a VERY large positve int. Neither of them
covers when it will not strip null fields. I forget the formal logic
syntax but it goes something like this:
A -> B != !A -> !B
-> means implies
! means not
= means equal
My version may be more confusing, however it is more complete, which
is always good. Just my $.02. Of course with Perl 6 coming out we may
see new docs for a lot of these operators, so maybe it's not worth
amending now anyway.
-Greg
------------------------------
Date: Mon, 01 Mar 2004 20:34:01 GMT
From: Joe Smith <Joe.Smith@inwap.com>
Subject: Re: Storing numbers in an array from files
Message-Id: <Z6N0c.156617$jk2.597266@attbi_s53>
aleatory wrote:
> | @line = $_; <--@line contains 1218, 8, 29
No, $line[0] contains "1218, 8, 29\n" and the rest of the array is empty.
> | @my_array = @line How could I store each as:
> | } $my_array[0] = 1218
> | $my_array[1] = 8
> | $my_array[2] = 29
@my_array = split /[,\s]/, $_; # Split on comma and/or whitespace.
-Joe
------------------------------
Date: Mon, 1 Mar 2004 20:48:23 -0000
From: "gnari" <gnari@simnet.is>
Subject: Re: Suggest a suitable image modifying CPAN module
Message-Id: <c207gq$fpt$1@news.simnet.is>
"Kasp" <kasp@epatra.com> wrote in message
news:c1vsrg$sod$1@newsreader.mailgate.org...
> Hello,
>
> Problem: I need a module that will put a user specified string in the
bottom
> right corner of an image (bmp, jpg, gif etc). Height of text will be 1/10
> height of image.
>
Image::Magick
and to some extent GD
gnari
------------------------------
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:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#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 V10 Issue 6200
***************************************