[12006] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5606 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Sat May 8 17:07:15 1999

Date: Sat, 8 May 99 14:00:18 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Sat, 8 May 1999     Volume: 8 Number: 5606

Today's topics:
    Re: A little light amusement (Matthew Bafford)
    Re: CGI timeout in web-based listserv (Robert Watkins)
    Re: CGI timeout in web-based listserv <design@raincloud-studios.com>
    Re: Copying Multidimensional Arrays <jdf@pobox.com>
        How do I assign multiple values to a single variable? <s@undersea.net>
    Re: How do I assign multiple values to a single variabl <walton@frontiernet.net>
    Re: How do I assign multiple values to a single variabl (Michel Dalle)
        how to compare two big files? bing-du@tamu.edu
    Re: HTML POST to Perl script problem <design@raincloud-studios.com>
    Re: https help (passme) (George)
        make install and INC (Pete Holsberg)
        Net::SMTP Problems.  Help ! <stevenmc@pacbell.net>
        Passing an array through wanted in File::Find <design@raincloud-studios.com>
    Re: Passing an array through wanted in File::Find <uri@sysarch.com>
    Re: Passing an array through wanted in File::Find <design@raincloud-studios.com>
    Re: PGP package doesn't install...need help (Alastair)
        Probelm using DBI in cgi scripts... ammar_aganovic@my-dejanews.com
        Problem in 'use Socket;' <cutekit@chollian.net>
        Problem in 'use Socket;' <cutekit@chollian.net>
    Re: regular expression question (Robert Watkins)
    Re: regular expression question <gellyfish@gellyfish.com>
    Re: Sorting is too slow for finding top N keys... - UPD (Michel Dalle)
        Sorting is too slow for finding top N keys... (Michel Dalle)
    Re: Sorting is too slow for finding top N keys... (Ilya Zakharevich)
        Time of execution of perl script <webmaster@gotspeed.com>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Sat, 08 May 1999 17:37:15 GMT
From: dragons@dragons.duesouth.net (Matthew Bafford)
Subject: Re: A little light amusement
Message-Id: <slrn7j8s1o.fd.dragons@dragons.duesouth.net>

On 8 May 1999 11:29:58 -0000, Jonathan Stowe <gellyfish@gellyfish.com>
lucked upon a computer, and thus typed in the following:
: Of course the more astute amongst you will be able to determine that
: this is a piece of C code that I have crudely ported to Perl ;-}

Nah, woulda never guessed. :-)
 
: Well we are on it - can anyone think of a way of allocating the colours
: in a nicer way ?

For some values of nicer:

@colours = map {
                    $image->colorAllocate(map {rand(256)} 1..3)
} 1 .. $max_colours;

Just as an idea, for things like this it'd probably be best to mark it
with [SRC] on the subject, or something like that so people can spot it
easier.

Thanks!

--Matthew


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

Date: Sat, 08 May 1999 17:30:14 GMT
From: r-watkins@worldnet.att.net (Robert Watkins)
Subject: Re: CGI timeout in web-based listserv
Message-Id: <7h1sbp$bem$1@bgtnsc02.worldnet.att.net>

In article <u9JY2.294$vP2.168@news.rdc1.tn.home.com>, "Charles R. Thompson" <design@raincloud-studios.com> wrote:
>>How can I get this to run such that the sender gets the "done" page rather
>>than a server error message?
>
[ snipped ]
>I'm not sure what side effect it would cause for the webserver daemon (having
>an open connection for too long?), but sending a confirmation for each ...
>make that every 25-50 or MORE email message via a print statement might keep
>the timeout from occuring. Ya think? Since your browser would be getting input
>every x seconds.. there should be no problem then.
>
>Messages 1-50 sent.
>Messages 51-100 sent.
>
>I do know if you put the results in a table, it won't display in the browser
>until the table tag is closed, but the communication will still be there.
>
>CT
>

Thank you, CT, this seems to do the trick. I say "seems" because so far I have 
only tested this on my development box, which is actually my laptop (running 
Apache for Win32 and ActiveState Perl). Because I can't run the thing on my 
laptop exactly the way I would in the real world, I made a list of more than 
15,000 e-mail addresses and wrote each message to disk. Without any 
modifications it did time out, so I figured it was a good approximation.

I first wrote into a single scalar as much of the message as possible 
(eveything except the e-mail address of the recipient) BEFORE the loop, to try 
to save on concatenation and calls to "print", but it was surprising how 
little time this saved (about 2%).

I then wrote a message for every 100 bulletins sent out. What I discovered 
(and probably should have known in the first place) is that the server only 
sends data to the browser when it has enough of a chunk (about 4 Kb, in this 
case) or when it knows there is no more to send. As such, a simple one line 
print statement was not enough. I ended up writing a lot of garbage (x's) 
within an html comment block (<!-- xxx -->) so that the message would update 
the browser with each turn.

All the best,
 -- Robert


--------------------------------
Robert Watkins
r-watkinsNO@SPAMworldnet.att.net
--------------------------------
"I must go seek some dew-drops here,
 And hang a Perl in evry cowslips ear."
                 -- William Shakespeare
   A Midsummer Night's Dream, II, i, 14


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

Date: Sat, 08 May 1999 18:05:54 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: CGI timeout in web-based listserv
Message-Id: <62%Y2.1092$vP2.316@news.rdc1.tn.home.com>

>I then wrote a message for every 100 bulletins sent out. What I
discovered
>(and probably should have known in the first place) is that the server
only
>sends data to the browser when it has enough of a chunk (about 4 Kb, in
this
>case) or when it knows there is no more to send. As such, a simple one
line
>print statement was not enough. I ended up writing a lot of garbage
(x's)
>within an html comment block (<!-- xxx -->) so that the message would
update
>the browser with each turn.


I would consider the end user's memory when taking this approach. I've
crunched IE many a day sending too much data to the browser. Maybe I'm
off (usually am) but I thought flushing the buffer at the top of a
script would send print commands right out to the browser when doing
something like this. I know I've seen incremental displays with less
than 4kb of data.

Are you sure it's the server and not something related to Perl's
handling of it?

CT




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

Date: 08 May 1999 13:07:10 -0400
From: Jonathan Feinberg <jdf@pobox.com>
To: jasonl@rand.org
Subject: Re: Copying Multidimensional Arrays
Message-Id: <m34slnmqwx.fsf@joshua.panix.com>

Jason Lingel <jasonl@rand.org> writes:

> How do you copy all of the values, not the memory addresses, from
> one (multidimensional) array to another (multidimensional) array?

perlfaq4: "How do I print out or copy a recursive data structure?"

-- 
Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
http://pobox.com/~jdf


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

Date: Sat, 08 May 1999 12:23:58 -0500
From: Sean <s@undersea.net>
Subject: How do I assign multiple values to a single variable?
Message-Id: <3734732E.32A38102@undersea.net>

Hi,
	I just have another quick question.  How do I assign the same value to
a list of scalar variables?  Right now I'm doing this, trying to assign
0 to the following variables with no success:

my ($var, $a, $b, $c, $d) = 0;

What is the correct/proper way to do this?  Thanks! 


--Sean


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

Date: Sat, 08 May 1999 16:13:25 -0400
From: Bob Walton <walton@frontiernet.net>
To: Sean <s@undersea.net>
Subject: Re: How do I assign multiple values to a single variable?
Message-Id: <37349AE5.7B6094A@frontiernet.net>

$var=$a=$b=$c=$d=0;

And, actually, if you just say

my($var,$a,$b,$c,$d);

the variables will all be initialized to undef, which is in many situations the
equivalent of zero.

Or if you mean that you actually have a perl list of variable references you want
to assign, try:

@list=(\$var,\$a,\$b,\$c,\$d); #set up the list of variable references
map {$$_=0} @list;

Sean wrote:

> Hi,
>         I just have another quick question.  How do I assign the same value to
> a list of scalar variables?  Right now I'm doing this, trying to assign
> 0 to the following variables with no success:
>
> my ($var, $a, $b, $c, $d) = 0;
>
> What is the correct/proper way to do this?  Thanks!
>
> --Sean



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

Date: Sat, 08 May 1999 20:22:53 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: How do I assign multiple values to a single variable?
Message-Id: <7h26da$t07$2@xenon.inbe.net>

In article <3734732E.32A38102@undersea.net>, Sean <s@undersea.net> wrote:
>Hi,
>        I just have another quick question.  How do I assign the same value to
>a list of scalar variables?  Right now I'm doing this, trying to assign
>0 to the following variables with no success:
>
>my ($var, $a, $b, $c, $d) = 0;
>
>What is the correct/proper way to do this?  Thanks! 

I don't know about the "proper" way, but these should work :

        my ($var, $a, $b, $c, $d) = (0) x 5;
or
        my ($var, $a, $b, $c, $d) = ( 0, 0, 0, 0, 0 );

Michel.


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

Date: Sat, 08 May 1999 20:31:12 GMT
From: bing-du@tamu.edu
Subject: how to compare two big files?
Message-Id: <7h26ug$1ut$1@nnrp1.deja.com>

Hello there,

Saloris 2.6, Perl 5.005

How to extract the differences and the intersection between two big files
(6M+)?

First, Unix 'diff' is one choice.  But the output of 'diff' is not that user
friendly. Secondly, inspired by perlfaq4::Data:Arrays::"How do I compute the
difference of two arrays?  How do I compute the intersection of two arrays?" 
I dumped two files into two arrays.  It was easy to manipulate arrays and
accomplished what I want.  But the potential problem is "Out of memory".  So
this method is also questionable.

Any suggests?  Thanks in advance,

Bing

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Sat, 08 May 1999 18:11:11 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: HTML POST to Perl script problem
Message-Id: <37%Y2.1105$vP2.426@news.rdc1.tn.home.com>

>> I've inherited a website with several Perl scripts and I'm not a Perl
>> programmer.  One html page calls a perl script using:
>> <form action="http://www.mysite.com/cgi_stuff/script.pl" method=post>
>> and I get the following error:
>> METHOD NOT ALLOWED
>> It is accessing the script in question.  It's on a UNIX-based server.
>> I've played with permissions but it hasn't helped.  Any ideas from
you
>> Perl gurus?


got get?

Try method="get" and see if that works. If not... you got troubles my
friend. :)

CT




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

Date: Sat, 08 May 1999 13:16:26 -0400
From: fred222@mauimail.com (George)
Subject: Re: https help (passme)
Message-Id: <fred222-ya023580000805991316260001@news.bellatlantic.net>

In article <7gvf37$qc0$1@nnrp1.deja.com>, mjz01@health.state.ny.us wrote:

> I need to check a server to see that it is up and running properly.

I'm the first to admit that I'm no perl genius, but the first thought to
strike me was that it might be simpler to try to ping the server to check
whether it's alive than to actually logon.  I'm sure there are modules or
example code to run a simple ping, since there are ping proggies
everywhere...  good luck!  Otherwise, at a guess, Lib-WWW-Perl (Library for
WWW access in Perl) might be a good bet to try.

Cheers,
George

-- 
Just another hacking head >l-d


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

Date: 8 May 1999 20:00:18 GMT
From: pjh@mccc.edu (Pete Holsberg)
Subject: make install and INC
Message-Id: <7h254i$j7q$1@lawrenceville.mccc.edu>

I have a module that doesn't install via make install. CAn
I just copy it to the directories that appear in @INC?

Thanks,
Pete


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

Date: Sat, 8 May 1999 12:25:04 -0700
From: "Steven McPherson" <stevenmc@pacbell.net>
Subject: Net::SMTP Problems.  Help !
Message-Id: <Lh0Z2.12530$ny.923772@typhoon-sf.snfc21.pbi.net>

Hi-

I seem to have problems with the Net::SMTP module included with LibNet.  My
script is pretty simple, and is a modification of one of the demos on the
ActiveState web site.  Here it is:

[][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][][

use Net::SMTP;


        $smtp = Net::SMTP->new('here.com'); # connect to an SMTP server
        $smtp->mail( 'user@here.com' );     # use the sender's address here
        $smtp->to('user@there.com');        # recipient's address
        $smtp->data();                      # Start the mail


        # Send the header.
        #
        $smtp->datasend("To: user@there.com\n");
        $smtp->datasend("From: user@here.com\n");
        $smtp->datasend("\n");


        # Send the body.
        #
        $smtp->datasend("Hello, World!\n");


        $smtp->dataend();                   # Finish sending the mail
        $smtp->quit;                        # Close the SMTP connection

[][][][][][][][][][][][][][][][][][][][][][][][

I've removed the e-mail addrs for security reasons, but when I run the
script, I get a couple of diff err msgs.  These include:

D:\Documents and Settings\stevenmc\My Documents\perl>mail.pl
In string, @there now must be written as \@there at D:\Documents and
Settings\st
evenmc\My Documents\perl\mail.pl line 12, near "To: user@there"
In string, @here now must be written as \@here at D:\Documents and
Settings\stev
enmc\My Documents\perl\mail.pl line 13, near "From: user@here"
Execution of D:\Documents and Settings\stevenmc\My Documents\perl\mail.pl
aborte
d due to compilation errors.

Any help would be appreciated.

Steve




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

Date: Sat, 08 May 1999 17:57:49 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Passing an array through wanted in File::Find
Message-Id: <xW_Y2.1090$vP2.154@news.rdc1.tn.home.com>

I admit confusion. I had about 25 lines of code for recursing
directories in a search script and decided to use File::Find instead.
Just for testing I was using my $scalars and @arrays outside of the
subroutines to get it functional. Now that I'm trying to actually scope
the variables inside the routines and pass them to findkeywords(), it's
breaking down.

I'm 98% certain my problem lies in misunderstanding the @_ $_ variables.
The docs say that File::Find assumes I'm not screwing with the $_
variable, but I need to pass an array of @keywords to &findkeywords()
and I think I'm wiping out the functionality of Find::File with $_ by
doing so. If I get the docs right, my goal here is to pass an array to
findkeywords, catch File::Find's usage of $_, do some processing, then
put $_ back where it belongs before I exit to sub.

I can understand passing a scalar and an array into a subroutine, but
the details get very sketchy for me with my newest predicament since I'm
not actually passing the default variable along. Some enlightenment
would be greatly appreciated.

CT

code snippets...

use File::Find;
find(\&findkeywords(@keyword_list), "/drv1/web/sites/web6517e/");

sub findkeywords{
  # ill fated attempt to think $_was the first thing in there.
  my ($temp_thing, @keywords) = @_;
  return unless ((/\.shtml.*$/) || (/cgi-bin/));

  # do stuff here to each valid page with @keywords.

  $_ = $temp_thing;
}






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

Date: 08 May 1999 15:05:58 -0400
From: Uri Guttman <uri@sysarch.com>
Subject: Re: Passing an array through wanted in File::Find
Message-Id: <x7pv4bs7op.fsf@home.sysarch.com>

>>>>> "CRT" == Charles R Thompson <design@raincloud-studios.com> writes:

  CRT> I'm 98% certain my problem lies in misunderstanding the @_ $_ variables.
  CRT> The docs say that File::Find assumes I'm not screwing with the $_
  CRT> variable, but I need to pass an array of @keywords to &findkeywords()
  CRT> and I think I'm wiping out the functionality of Find::File with $_ by
  CRT> doing so. If I get the docs right, my goal here is to pass an array to
  CRT> findkeywords, catch File::Find's usage of $_, do some processing, then
  CRT> put $_ back where it belongs before I exit to sub.

first off, $_ and @_ are not related at all. you use @_ for all sub
arguments as it is localized to each sub (assuming args are passed in;
calling &foo will allow the current value of @_ to be used). $_ is never
used by perl in argument passing. it is a single global scalar used by
default in many ops and in for loops, while(<>), map & grep, etc. 

so File::Find sets $_ to the current filename in the current dir
$File::Find::dir. consider it a global argument to your findkeywords
sub. once you have that value, you could localize $_ and use it
internally for your code.

  CRT> use File::Find;
  CRT> find(\&findkeywords(@keyword_list), "/drv1/web/sites/web6517e/");

  CRT> sub findkeywords{
  CRT>   # ill fated attempt to think $_was the first thing in there.
  CRT>   my ($temp_thing, @keywords) = @_;

no need for $temp_thing

  CRT>   return unless ((/\.shtml.*$/) || (/cgi-bin/));

that line will work since $_ is the current file

next try this here:

	my ($curr_file) = $_ ;

	{ local $_ ;

  CRT>   # do stuff here to each valid page with @keywords.

	you can use $_ in all code and subs here

	}

	now $_ is back to the current file

hth,

uri

-- 
Uri Guttman  -----------------  SYStems ARCHitecture and Software Engineering
uri@sysarch.com  ---------------------------  Perl, Internet, UNIX Consulting
Have Perl, Will Travel  -----------------------------  http://www.sysarch.com
The Best Search Engine on the Net -------------  http://www.northernlight.com


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

Date: Sat, 08 May 1999 20:24:06 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Passing an array through wanted in File::Find
Message-Id: <G31Z2.1125$vP2.512@news.rdc1.tn.home.com>

>so File::Find sets $_ to the current filename in the current dir
>$File::Find::dir. consider it a global argument to your findkeywords
>sub. once you have that value, you could localize $_ and use it
>internally for your code.


Hmmm.. that didn't seem to do it. The default variable is getting
wiped out. Either I'm whacky, or it is. ~:) (Prolly me) I added the
'appropriate info' in the script to give a larger picture if it has
anythign to do with the problem.

searchsite is called to search the site which in turn passes the info
to findkeywords on each file.

CT

snippets...

sub searchsite{

my $thekeywords = $query->param('q');
# this needs work.
my @keyword_list = split(/\s+/,$thekeywords);
# some basic error checking =~ here for blank keywords...

use File::Find;
find(\&findkeywords(@keyword_list), "/drv1/web/sites/web6517e/");

# after search results stuff...
}


sub findkeywords{
  my @keywords = @_;

  # Test1 - Reveals keywords are passed, so obviously we can do that.
  foreach $word(@keywords){
    print $word . "<br>";
  }

  # Test2 - Reveals default variable is blank? Wha?
  print "Filename checked is $_ <br>";

  # everything below never gets a chance, exits after first find.
  # I removed the test code and it still behaved in the same manner.
  # if I use @keyword_list in a larger scope instead of passing it
  # then the code works fine. Is there something techhy involved in
  # passing an array through the File::Find 'findkeywords' that
  # is doing this?

  return unless ((/\.shtml.*$/) || (/cgi-bin/));

  my ($curr_file) = $_;


    local $_;
    my (@pagelines) = ();
    my $pagelines = "";

    open(SEARCHFILE, "$curr_file") || die;
      @pagelines = <SEARCHFILE>;
    close (SEARCHFILE) || die;

    # slurp.
    $pagelines = join('', @pagelines);

    # processing stuff follows...

  }
  # $_ is what it was before now
}





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

Date: Sat, 08 May 1999 19:13:11 GMT
From: alastair@calliope.demon.co.uk (Alastair)
Subject: Re: PGP package doesn't install...need help
Message-Id: <slrn7j96oj.5v.alastair@calliope.demon.co.uk>

Pete Holsberg <pjh@mccc.edu> wrote:
>
>I take it that I cannoy just create the directories and
>copy Pipe.pm to them?

Maybe. I'd be worried that this particular 'Pipe.pm' has nothing to do with
IO::Pipe though. 

>Is there another PGP module that does PGP?

The only other module I saw related to PGP was 'PGP::Sign'. Not looking
promising ...

Best Wishes,

-- 

Alastair
work  : alastair@psoft.co.uk
home  : alastair@calliope.demon.co.uk


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

Date: Sat, 08 May 1999 18:28:09 GMT
From: ammar_aganovic@my-dejanews.com
Subject: Probelm using DBI in cgi scripts...
Message-Id: <7h1vnm$s5u$1@nnrp1.deja.com>

Thisis my problem. I've got a MySQL database on the system and I wrote a test
script in perl with DBI module to see if it is running OK before deploying it
to web. So I wrote the connects and fetcharrays and it worked fine.

So I tried to deploy it, but it doesn't work! Everything under the execute
statement command is not beeing interpreted, as if the excute command kills
the Apache connection.

Is anyone expiriencing similar problems? What should I do?
I am running Apache 1.3.6 with PHP3 and other goodies.
HELP!

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    


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

Date: Thu, 6 May 1999 17:54:55 +0900
From: "Park, Byung-Jae" <cutekit@chollian.net>
Subject: Problem in 'use Socket;'
Message-Id: <7grl2j$cel$1@newsread.unitel.co.kr>

My name is Park, and e-mail is cutekit@chollian.net.

I want to make a program using Socket. But I got a problom.
My simple perl source is below.

require 5.002;
use strict;
use sigtrap;
use Socket;
print "hahaha\n";

And errors are below.

Use of uninitialized value at /usr1/pbj/perl/lib/5.00502/Socket.pm line 118.
Use of uninitialized value at /usr1/pbj/perl/lib/5.00502/Socket.pm line 118.
Socket version 1.3 required--this is only version  at
/usr1/pbj/perl/lib/5.00502/Socket.pm line 118.
BEGIN failed--compilation aborted at /usr1/pbj/perl/lib/5.00502/Socket.pm
line 118.
BEGIN failed--compilation aborted at t.pl line 4.

The line 118 of Socket.pm is "use Socket 1.3;".

I don't know what's the matter. Somebody help!!!!

^_^




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

Date: Fri, 07 May 1999 09:08:15 +0900
From: "Park, Byung-Jae" <cutekit@chollian.net>
Subject: Problem in 'use Socket;'
Message-Id: <37322EEE.AF1EBD4F@chollian.net>

My name is Park, and e-mail is cutekit@chollian.net.

I want to make a program using Socket. But I got a problem.
My simple perl source is below.

>require 5.002;
>use strict;
>use sigtrap;
>use Socket;
>print "hahaha\n";

And errors are below.

>Use of uninitialized value at /usr1/pbj/perl/lib/5.00502/Socket.pm line
118.
>Use of uninitialized value at /usr1/pbj/perl/lib/5.00502/Socket.pm line
118.
>Socket version 1.3 required--this is only version  at
/usr1/pbj/perl/lib/5.00502/Socket.pm line 118.
>BEGIN failed--compilation aborted at
/usr1/pbj/perl/lib/5.00502/Socket.pm line 118.
>BEGIN failed--compilation aborted at t.pl line 4.

The line 118 of Socket.pm is "use Socket 1.3;".

I don't know what's the matter. Somebody help!!!!

^_^





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

Date: Sat, 08 May 1999 17:34:45 GMT
From: r-watkins@worldnet.att.net (Robert Watkins)
Subject: Re: regular expression question
Message-Id: <7h1sk7$bem$2@bgtnsc02.worldnet.att.net>

In article <373462BA.5CB4114C@rc3.org>, Rafe Colburn <rafeco@rc3.org> wrote:
> I'm using this regular expression to parse some code (specifically to
>extract variable names and types):
> 
>code =~ /(procedure\s+(\w+)\s*\(.*\))/gi
> 
> it matches this:
> 
>procedure register(name in varchar2)
> 
>but not this:
> 
>procedure waitone(name in varchar2, 
>                  message out varchar2, 
>                  status out integer,
>                  timeout in number default maxwait)
> 
>  The code is all in one huge string.  Do I have to tell it something
>special to get it to cross line feeds?  I thought that the .* would
>just do it.
>

Use the "s" modifier (page 69++ in the Camel book):

$code =~ /(procedure\s+(\w+)\s*\(.*\))/gis


--------------------------------
Robert Watkins
r-watkinsNO@SPAMworldnet.att.net
--------------------------------
"I must go seek some dew-drops here,
 And hang a Perl in evry cowslips ear."
                 -- William Shakespeare
   A Midsummer Night's Dream, II, i, 14


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

Date: 8 May 1999 18:43:48 -0000
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: regular expression question
Message-Id: <7h20l4$3hn$1@gellyfish.btinternet.com>

On Sat, 08 May 1999 12:13:46 -0400 Rafe Colburn wrote:
>  I'm using this regular expression to parse some code (specifically to
> extract variable names and types):
>  
> code =~ /(procedure\s+(\w+)\s*\(.*\))/gi
>  
>  it matches this:
>  
> procedure register(name in varchar2)
>  
> but not this:
>  
> procedure waitone(name in varchar2, 
>                   message out varchar2, 
>                   status out integer,
>                   timeout in number default maxwait)
>  
>   The code is all in one huge string.  Do I have to tell it something
> special to get it to cross line feeds?  I thought that the .* would
> just do it.
> 

Check out the perlre manpage with special attention to what it says
about the /s modifier.

The problem with this sort of thing is that you rapidly get into
developing a full-blown parser for the language - I started at a little
poke at this :


#!/usr/bin/perl -w

use strict;

my @example;

$example[0] = 'procedure register(name in varchar2)';

$example[1] =<<'EIEIO';
procedure waitone(name in varchar2,
                  message out varchar2,
                  status out integer,
                  timeout in number default maxwait)
EIEIO

foreach (@example)
{
   if($_ =~ /procedure\s*(\S+)\s*\((.*?)\)/is)
     {
       my $arglist;
       my $procedure = $1;
       print "Procedure:  $procedure\n"; 
       my @args = split /\s*,\s*\n\s*/s,$2;
       foreach $arglist (@args)
        {
          print "\tParam : $arglist\n";
        }
     }
}

And then you start to get into deep water ....

/J\
-- 
Jonathan Stowe <jns@gellyfish.com>
Some of your questions answered:
<URL:http://www.btinternet.com/~gellyfish/resources/wwwfaq.htm>
Hastings: <URL:http://www.newhoo.com/Regional/UK/England/East_Sussex/Hastings>


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

Date: Sat, 08 May 1999 20:16:09 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Re: Sorting is too slow for finding top N keys... - UPDATE
Message-Id: <7h260m$t07$1@xenon.inbe.net>

In article <7h24na$sfp$1@xenon.inbe.net>, michel.dalle@usa.net (Michel Dalle) wrote:
>Hi,
>
>I've had a funny experience with using sort. Can anyone tell
>me why perl sorts so slowly sometimes, depending on the
>values to be sorted ?
>
>Here's what happened : I have a hash with about 30.000 entries,
>I want to sort them by value and extract the top N elements.
>The hash contains about 500 different values, and the majority
>of values are all the same (=heavy-tailed distribution?).
>
>1) the simple (obvious) way would be to let Perl do the job :
>
>@topn = (sort {$hash{$b} <=> $hash{$a}} keys %hash)[0..$n];
>
>This works fine for random values (a few seconds), but for the
>hash I have, it takes several minutes !!
>
>2) since this was quite unacceptable, I ended up writing my own
>top N sort routine :
>
>@topn = ();
>$count=0;
>foreach $key (keys %hash) {
>        if ($count <= $n) {
>                push(@topn,$key);
>        }
>        else {
>                @topn = (sort {$hash{$b} <=> $hash{$a}} @topn,$key)[0..$n];
>        }
>        $count++;
>}
>
>I also tried replacing the sort with pops, splices and unshifts, but it didn't
>really improve anything. Can anyone suggest other alternatives ?

I forgot to mention my third test :

3) forget about the sort in Perl, and build my own :

@topn = ();
$count = 0;
while (($key,$val) = each %hash) {
        if ($count <= $n) {
                push(@topn,$key);
                if ($count == $n) {
                        @topn = (sort {$hash{$b} <=> $hash{$a}} @topn);
                }
        }
        else {
                if ($val > $hash{$topn[0]}) {
                        pop(@topn);
                        unshift(@topn,$key);
                }
                elsif ($val < $hash{$topn[$n]}) {
                }
                else {
                        for ($i = 1; $i < $n; $i++) {
                                if ($val > $hash{$topn[$i]}) {
                                        last;
                                }
                        }
                        splice(@topn,$i,0,$key);
                        pop(@topn);
                }
        }
        $count++;
}

This one sorts my 30.000+ hash in 3 seconds, the previous one in 45 seconds,
and the first one in xxx minutes, for a top 20.

Any comments ?

Michel.

--
aWebVisit - extracts visitor information from WWW logfiles and shows
the top entry, transit, exit and 'hit&run' pages, the links followed
inside your website, the time spent per page, the visit duration etc.
For more details, see http://gallery.uunet.be/Michel.Dalle/awv.html


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

Date: Sat, 08 May 1999 19:54:04 GMT
From: michel.dalle@usa.net (Michel Dalle)
Subject: Sorting is too slow for finding top N keys...
Message-Id: <7h24na$sfp$1@xenon.inbe.net>

Hi,

I've had a funny experience with using sort. Can anyone tell
me why perl sorts so slowly sometimes, depending on the
values to be sorted ?

Here's what happened : I have a hash with about 30.000 entries,
I want to sort them by value and extract the top N elements.
The hash contains about 500 different values, and the majority
of values are all the same (=heavy-tailed distribution?).

1) the simple (obvious) way would be to let Perl do the job :

@topn = (sort {$hash{$b} <=> $hash{$a}} keys %hash)[0..$n];

This works fine for random values (a few seconds), but for the
hash I have, it takes several minutes !!

2) since this was quite unacceptable, I ended up writing my own
top N sort routine :

@topn = ();
$count=0;
foreach $key (keys %hash) {
        if ($count <= $n) {
                push(@topn,$key);
        }
        else {
                @topn = (sort {$hash{$b} <=> $hash{$a}} @topn,$key)[0..$n];
        }
        $count++;
}

I also tried replacing the sort with pops, splices and unshifts, but it didn't
really improve anything. Can anyone suggest other alternatives ?

Michel.

--
aWebVisit - extracts visitor information from WWW logfiles and shows
the top entry, transit, exit and 'hit&run' pages, the links followed
inside your website, the time spent per page, the visit duration etc.
For more details, see http://gallery.uunet.be/Michel.Dalle/awv.html


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

Date: 8 May 1999 20:13:44 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Sorting is too slow for finding top N keys...
Message-Id: <7h25to$ld2$1@mathserv.mps.ohio-state.edu>

[A complimentary Cc of this posting was sent to Michel Dalle
<michel.dalle@usa.net>],
who wrote in article <7h24na$sfp$1@xenon.inbe.net>:
> Hi,
> 
> I've had a funny experience with using sort. Can anyone tell
> me why perl sorts so slowly sometimes, depending on the
> values to be sorted ?
> 
> Here's what happened : I have a hash with about 30.000 entries,
> I want to sort them by value and extract the top N elements.
> The hash contains about 500 different values, and the majority
> of values are all the same (=heavy-tailed distribution?).
> 
> 1) the simple (obvious) way would be to let Perl do the job :
> 
> @topn = (sort {$hash{$b} <=> $hash{$a}} keys %hash)[0..$n];
> 
> This works fine for random values (a few seconds), but for the
> hash I have, it takes several minutes !!

Upgrade?

Ilya


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

Date: Sat, 8 May 1999 15:56:41 -0400
From: "Deepak" <webmaster@gotspeed.com>
Subject: Time of execution of perl script
Message-Id: <926193457.898.102@news.remarQ.com>

I have a perl script that searches a flat text file and returns the results.
How can I time from the open of the file until the summary,
printing the # of seconds(probably need about 5 decimals places, because it
does not take long) it took for the query.

Deepak




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

Date: 12 Dec 98 21:33:47 GMT (Last modified)
From: Perl-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin) 
Subject: Special: Digest Administrivia (Last modified: 12 Dec 98)
Message-Id: <null>


Administrivia:

Well, after 6 months, here's the answer to the quiz: what do we do about
comp.lang.perl.moderated. Answer: nothing. 

]From: Russ Allbery <rra@stanford.edu>
]Date: 21 Sep 1998 19:53:43 -0700
]Subject: comp.lang.perl.moderated available via e-mail
]
]It is possible to subscribe to comp.lang.perl.moderated as a mailing list.
]To do so, send mail to majordomo@eyrie.org with "subscribe clpm" in the
]body.  Majordomo will then send you instructions on how to confirm your
]subscription.  This is provided as a general service for those people who
]cannot receive the newsgroup for whatever reason or who just prefer to
]receive messages via e-mail.

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.misc (and this Digest), send your
article to perl-users@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.

The Meta-FAQ, an article containing information about the FAQ, is
available by requesting "send perl-users meta-faq". The real FAQ, as it
appeared last in the newsgroup, can be retrieved with the request "send
perl-users FAQ". Due to their sizes, neither the Meta-FAQ nor the FAQ
are included in the digest.

The "mini-FAQ", which is an updated version of the Meta-FAQ, is
available by requesting "send perl-users mini-faq". It appears twice
weekly in the group, but is not distributed in the digest.

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 V8 Issue 5606
**************************************

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