[19986] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 2181 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 22 11:05:40 2001

Date: Thu, 22 Nov 2001 08:05:07 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006445107-v10-i2181@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Thu, 22 Nov 2001     Volume: 10 Number: 2181

Today's topics:
    Re: Do Not Redirect CGI Questions To CIWAC (Randal L. Schwartz)
        eval or not eval <mr.thanquol@gmx.de>
    Re: Fastest way to eliminate words < 4 characters long  (Tad McClellan)
    Re: Fastest way to eliminate words < 4 characters long  <5l259r001@sneakemail.com>
        fork() difference between Win and Linux/Unix <zoltan.kandi@tellabs.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: 22 Nov 2001 07:40:27 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Do Not Redirect CGI Questions To CIWAC
Message-Id: <m1bshurez8.fsf@halfdome.holdit.com>

>>>>> "Godzilla!" == Godzilla!  <godzilla@stomp.stomp.tokyo> writes:

Godzilla!> I will state again what I have recently stated.
Godzilla!> Do not redirect people with cgi questions to
Godzilla!> the comp.infosystems.www.authoring.cgi group.

Ahh yes.  The Consensus of One.

As a counter-suggestion, I propose that people continue the reasonably
appropriate behavior of the status quo, which is to redirect people to
a different group if the topic is appropriate.

Godzilla!> Reasons for this are very apparent.

Really?  Not apparent to me.  CIWAC is functioning just fine, although
the boutell-bot outage was a bit troublesome.  Sheila stepping in to
provide a replacement was a very needed thing.

Godzilla!> Anyone care to present an argument, a rational
Godzilla!> argument having an auto-bot moderated newsgroup
Godzilla!> is both a logical idea and a good idea?

That topic is off-topic here.  And already discussed to death
in CIWAC.  Please take your discussion *back* there.

Godzilla!> I certainly have acted in a responsible manner
Godzilla!> by investing a lot of time and effort into
Godzilla!> trying to restore the cgi group. Have you?

It's not a responsible manner to have brought it into a different
arena.  It's also not a responsible manner to oppose the efforts of
Sheila, who is doing a fine volunteer job of getting *some* form of
moderating-bot up and running again to revive the group.

Changing the location of a bot is easy.  Changing a group from
moderated to unmoderated is Very Very Difficult because of the
lame admins out there.

But you were told this already in that group.  Don't bring the
discussion here.  {sigh}

-- 
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!


------------------------------

Date: Thu, 22 Nov 2001 16:53:56 +0100
From: "felix" <mr.thanquol@gmx.de>
Subject: eval or not eval
Message-Id: <9tj72q$5it$1@crusher.de.colt.net>

hi,

I finally reached a point where I can't concentrate any more! I'm trying to
read stuff from a config-file
and put it in hashes and scalars...just an example

conf-file
========>>>

WebSite
apache        =        http://www.apache.org
perl              =        http://www.perl.com

OS
solaris            =        http://www.sun.com/solaris
suse-linux      =        http://www.suse.com

logfile             =        /tmp/log.file
 ....
<<<========

what I want is to get the following

%WebSite  (which contains  apache => 'http://www.apache.org' and perl =>
'http://www.perl.com')
%OS            (solaris => 'http://www.sun.com/solaris' ....)
$logfile        ('/tmp/log.file')

I think about using eval like in a shell script but I didn't found the
correct combination yet...

thx
fe







------------------------------

Date: Thu, 22 Nov 2001 15:32:52 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Fastest way to eliminate words < 4 characters long except month abbreviations?
Message-Id: <slrn9vq0ag.sk5.tadmc@tadmc26.august.net>

Bob <null@null.com> wrote:
>
>I wrote a search engine script which only indexes words of 4 characters or
>more or the 3 character month abbreviation of the time stamp in order to
>reduce the size of the index. For simplicity the script only returns
>results which match all search terms. Because of the last feature I have
>to remove all search terms of 3 characters or less excepting monthly
                                                    ^^^^^^^^^
>abbreviations or that search will not return any results. 


Also excepting runs of 1, 2 or 3 digit chars, I assume from
your regex below.


>I am currently
>using this regex to accomplish this:
>
>@searchterms = ($userinput =~
>m/\w{4,}|\d+|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/g);
>
>My impression as a perl newbie is that regex's are very slow 


How have you formed that impression?

By observing program behavior, or by thinking about how pattern
matching works or something?

How fast it is depends a great deal on both the pattern and the
data to match against, so you can't analyse the speed sensibly
without consideration of both.


>and I suspect
>that this particular regex is extremely slow. 


What do you see that makes you think it will be slow?

When I look at it, it looks like it ought to be right snappy, as
there is little opportunity for backtracking.

But I could be wrong. Analysing the performance of pattern
matching makes my head hurt...


>The only other way of doing
>this that I can think of is to use a foreach loop to search through every
>month and I have no idea if this would actually be faster. 


You can use the Benchmark module to compare each approach using
your real data.


>Any advice on
>which of the two methods I have mentioned is fastest or describing a third
>and faster method would be appreciated.


So you have already established via testing or actual use that
you do indeed need it to run faster?


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Thu, 22 Nov 2001 16:36:45 +0100
From: "Steffen Müller" <5l259r001@sneakemail.com>
Subject: Re: Fastest way to eliminate words < 4 characters long except month abbreviations?
Message-Id: <9tj60h$tqk$04$1@news.t-online.com>

"Bob" <null@null.com> schrieb im Newsbeitrag
news:null-2211010040020001@user161.lwpw-01.cwia.com...
|
| I wrote a search engine script which only indexes words of 4 characters or
| more or the 3 character month abbreviation of the time stamp in order to
| reduce the size of the index. For simplicity the script only returns
| results which match all search terms. Because of the last feature I have
| to remove all search terms of 3 characters or less excepting monthly
| abbreviations or that search will not return any results. I am currently
| using this regex to accomplish this:
|
| @searchterms = ($userinput =~
| m/\w{4,}|\d+|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/g);

#!/bin/perl
use strict;
use warnings;
use Benchmark;

my @words;
my $string = 'dasdjasl dec ads das, aa,  mar APR, das oCt asjkld'x1000;

my $count = 1000;

my %allowed =
(jan=>undef,feb=>undef,mar=>undef,apr=>undef,may=>undef,jun=>undef,

jul=>undef,aug=>undef,sep=>undef,oct=>undef,nov=>undef,dec=>undef);

timethese( $count, {
   'your regex' => sub {
                      @words = ($string =~

m/\w{4,}|\d+|jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec/g);
                      # this only matches lower case months!
                   },
   'hash_grep'  => sub {
                      @words = ($string =~ m/\w{3,}/g);
                      @words = grep(
                        ( length $_ > 3 || exists($allowed{$_}) ),
                         @words
                      );
                   },
   'push'       => sub {
                      @words = ($string =~ m/\w{4,}/g);
                      push @words,
                        'jan','feb','mar','apr','may',
                        'jun','jul','aug','sep','oct','nov','dec';
                   }
} )


__END__

prints on my computer:

Benchmark: timing 1000 iterations of hash_grep, push, your regex...
 hash_grep: 67 wallclock secs (56.73 usr +  0.02 sys = 56.75 CPU) @ 17.62/s
(n=1
000)
      push: 15 wallclock secs (13.19 usr +  0.01 sys = 13.20 CPU) @ 75.76/s
(n=1
000)
your regex: 93 wallclock secs (76.29 usr +  0.06 sys = 76.35 CPU) @ 13.10/s
(n=1
000)

HTH,
Steffen
--
$_=q;0cb212c210b0bb010c0113bb0c410c0b516c0bb3d212c2b0b0b016b6cb2b2c21010c0
b41110b3bba0e0c0d2c4b2b6bc013d2c0d0b01012b0b0;;s/\n//g;s/(\d)/$1<2?$1:'0'x
$1/ge;s/([a-f])/'1'x(ord($1)-97)/ge;$o=$_;push@o,substr($o,$_*8,8) for(0..
24);for(@o){print"\0"x(26-$i).chr(oct('0b'.($_)))."\r";$i++};print"\n"#stm





------------------------------

Date: Thu, 22 Nov 2001 15:30:42 GMT
From: Zoltan Kandi <zoltan.kandi@tellabs.com>
Subject: fork() difference between Win and Linux/Unix
Message-Id: <3BFD2736.3FB9D532@tellabs.com>

Hi all,

below script 

> #!perl
> 
> $pid = fork;
> 
> if (!$pid) {
> sleep(5);
> exit();
> }
> 
> print "parent waits for process $pid...\n";
> waitpid $pid, 0;
> print "child1 has finished\n";
> 
> $pid = fork;
> 
> if (!$pid) {
> sleep(5);
> exit();
> }
> 
> print "parent doesn't wait for process $pid this time...\n";
> kill "KILL", $pid;
> print "child1 is killed\n";
> 
> $pid = wait;
> if ($pid == -1) { print "no more children\n" }


has been run on Linux and produced the following output:

> parent waits for process 17037...
> child1 has finished
> parent doesn't wait for process 17038 this time...
> child1 is killed

and on WinNT 4.0 ActivePerl 5.6:

> parent waits for process -257...
> child1 has finished
> parent doesn't wait for process -712 this time...
> child1 is killed
> no more children

Apart from the PID there's one more difference, the Win32 run produced
one extra line "no more children". My question: is the ActiveState Win32
fork() command 100% compatible with the Unix implementation of fork()? 

Maybe this is the reason why the following script 

> # as seen at http://www.perldoc.com/perl5.6/pod/perlipc.html#Internet-TCP-Clients-and-Servers
> #!perl -w
> use strict;
> use IO::Socket;
> my ($host, $port, $kidpid, $handle, $line);
> 
> unless (@ARGV == 2) { die "usage: $0 host port" }
> ($host, $port) = @ARGV;
> 
> $handle = IO::Socket::INET->new(Proto     => "tcp",
>                                 PeerAddr  => $host,
>                                 PeerPort  => $port)
>        || die "can't connect to port $port on $host: $!";
> $handle->autoflush(1);
> print STDERR "[Connected to $host:$port]\n";
> 
> die "can't fork: $!" unless defined($kidpid = fork());
> 
> # the if{} block runs only in the parent process
> if ($kidpid) {
>     while (defined ($line = <$handle>)) {
>         print STDOUT $line;
>     }
>     kill("TERM", $kidpid);
> }
> else {
>     while (defined ($line = <STDIN>)) {
>         print $handle $line;
>     }
> }
> 

works perfectly on Linux providing communication in both direction,
while when run on WinNT 4.0, receives the welcome message from the host
I'm connecting to, and when I'm typing in a command, the whole thing
hangs...

TIA,

-- 
Zoltan Kandi, M. Sc.
Product & Application Specialist

Tellabs Netherlands BV
Perkinsbaan 17
3439 ND Nieuwegein

Tel:      +31 30 600 40 75
Fax:      +31 30 600 40 90
GSM:      +31 651 194 291
Email:    Zoltan.Kandi@tellabs.com
Internet: http://www.tellabs.com


------------------------------

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.  

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 2181
***************************************


home help back first fref pref prev next nref lref last post