[19609] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 1804 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Sep 24 11:06:49 2001

Date: Mon, 24 Sep 2001 08:05:10 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1001343910-v10-i1804@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Mon, 24 Sep 2001     Volume: 10 Number: 1804

Today's topics:
    Re: a bit of help please. <na>
    Re: a bit of help please. <Rainer.Klier@erl.sbs.de>
    Re: a bit of help please. <tinamue@zedat.fu-berlin.de>
    Re: alternatives to ps command (Martien Verbruggen)
    Re: alternatives to ps command (Ilja Tabachniks)
    Re: alternatives to ps command (Martien Verbruggen)
        As simply as I can put it.. <Kalle Anka@markisspecialisten.com>
    Re: As simply as I can put it.. <bart.lateur@skynet.be>
    Re: Best way to hide the perl source code.. (Brian Duffy)
    Re: eval-statement fools garbage-collection ? (Martien Verbruggen)
    Re: File compression (darrin)
    Re: How to remove whitespace without losing the 'real'  <bart.lateur@skynet.be>
    Re: New To Perl Scripting (Brian Duffy)
        Perl script for monitoring a web page? <andrey@flyg.kth.se>
    Re: Perl script for monitoring a web page? (Clinton A. Pierce)
    Re: Perl script for monitoring a web page? <bart.lateur@skynet.be>
    Re: Please Help with Sockets! <simon.oliver@umist.ac.uk>
    Re: Processing page between two other pages. (Phil Hibbs)
    Re: Q: How to "reserve" processes (Clinton A. Pierce)
    Re: sub key index sorting <bwalton@rochester.rr.com>
        The joys of segmentation faults <nobody@nowhere.com>
    Re: The joys of segmentation faults <ilya@martynov.org>
    Re: The joys of segmentation faults <ilya@martynov.org>
    Re: threads (Martien Verbruggen)
    Re: What good is the hyphen for named parameters? <mjcarman@home.com>
    Re: What good is the hyphen for named parameters? <ilya@martynov.org>
    Re: What good is the hyphen for named parameters? <simon.oliver@umist.ac.uk>
    Re: What good is the hyphen for named parameters? <bart.lateur@skynet.be>
    Re: win32 stat in directory with 4682 files <peter_korman@lotus.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 24 Sep 2001 14:17:19 +0100
From: "NEWS" <na>
Subject: Re: a bit of help please.
Message-Id: <3baf3262$0$227$ed9e5944@reading.news.pipex.net>

thanks that is really handy, but for example how would i make the
clock/timer count in 10's but by the second?

10
20
30
40 would be 4 secs

but replacing the previous output rather than with a new line ?

"Dave Tweed" <dtweed@acm.org> wrote in message
news:3BAF28FD.92C2AB23@acm.org...
> Paul Boardman wrote:
> > #!/usr/bin/perl -w
> > use strict;
> >
> > my $i = 0;
> > while(1){
> >         print $i++;
> >         sleep(1);
> > }
>
> Although this will count at a rate of *about* one count per second,
> it isn't counting in seconds. This would be better:
>
> my $start = time;
> $| = 1; # force flushing of output
> while (1) {
>     print "\r", time - $start;
>     sleep(1);
> }
>
> -- Dave Tweed




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

Date: Mon, 24 Sep 2001 14:57:46 -0100
From: Rainer Klier <Rainer.Klier@erl.sbs.de>
Subject: Re: a bit of help please.
Message-Id: <3BAF57FA.FF03BB08@erl.sbs.de>

NEWS wrote:
> 
> thanks that is really handy, but for example how would i make the
> clock/timer count in 10's but by the second?
> 
> 10
> 20
> 30
> 40 would be 4 secs

#!/usr/bin/perl -w

use Time::HiRes qw(usleep);

$i = 0;
while($i++ < 40) {
    print "$i\n" if(not $i % 10);
    usleep(100000);
}

Regards, Rainer


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

Date: 24 Sep 2001 13:53:35 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: a bit of help please.
Message-Id: <9ondsu$dm3e1$1@fu-berlin.de>

please don't TOFU.

NEWS <na> wrote:
> thanks that is really handy, but for example how would i make the
> clock/timer count in 10's but by the second?

> 10
> 20
> 30
> 40 would be 4 secs

> but replacing the previous output rather than with a new line ?

$|=1;
my $i=0;
while(1) {
  $i+=10;
  print "\r$i";
  sleep 1
}

hth, tina

-- 
http://www.tinita.de \  enter__| |__the___ _ _ ___
tina's moviedatabase  \     / _` / _ \/ _ \ '_(_-< of
search & add comments  \    \ _,_\ __/\ __/_| /__/ perception


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

Date: Mon, 24 Sep 2001 23:37:20 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: alternatives to ps command
Message-Id: <slrn9qudog.8ai.mgjv@martien.heliotrope.home>

On Mon, 24 Sep 2001 11:11:55 GMT,
	Tim Hammerquist <tim@vegeta.ath.cx> wrote:
> Me parece que perl misk <perlmisk@yahoo.co.uk> dijo:
>> as i understand it, it is considered "bad practice" to use shell or
>> system commands.
> 
> I found another reason it's a bad idea while looking into your problem.
> See below.
> 
>> I am trying to get a process listing, but cannot find an alternative
>> to `ps -fu`.  This isn't so much a problem until:
> 
> Here's a portion of the output of `ps -fu` in a bash session on my linux
> box:

> OTOH, ps seems to always be proprietary in implementation (and,
> unfortunately, interface). My ps manpage suggests proc(5), the proc
> pseudo-filesystem.  This may be a more portable solution, if the target
> OS supports it.  Some versions of ps also allow you to specify the
> format of its output. You may want to look into this as well.

Unfortunately, the various /proc filesystems on the various OSes are
even less portable than the output of ps. There was a thread as part of
which this came up a week or so ago on this group.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Useful Statistic: 75% of the people
Commercial Dynamics Pty. Ltd.   | make up 3/4 of the population.
NSW, Australia                  | 


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

Date: 24 Sep 2001 06:40:02 -0700
From: billy@arnis-bsl.com (Ilja Tabachniks)
Subject: Re: alternatives to ps command
Message-Id: <5d4a715a.0109240540.7ae1a16f@posting.google.com>

perlmisk@yahoo.co.uk (perl misk) wrote in message news:<7fe42fcd.0109240201.7a6f98c2@posting.google.com>...
> as i understand it, it is considered "bad practice" to use shell or
> system commands.
> 
> I am trying to get a process listing, but cannot find an alternative
> to `ps -fu`.  This isn't so much a problem until:
> 
> # grab the output from the ps command
> my $ps = `ps -fu$user`;
> 
> # convert our scalar $ps into an array, break on \n
> my @aps = split /\n/, $ps;
> 
> # loop each real processes
> foreach my $iaps (@aps) {
>  
>     # these are the only elements we require
>     my ($stime, $time, $cmd);               
> 
>     # loop each possible process type
>     foreach my $p (@processes) {
> 
>         # match the elements we require
>         if ($iaps =~
> m/^\s+\w+\s+\d+\s+\d+\s+\d+\s+([\d:]+)\s.+\s([\d:]+)\s(.+)$/) {
> 
>             # save the values we have matched from above regex
>             $cmd   = $3; $stime = $1; $time  = $2;
> 
>         }
> 
>     }
>  
> }
> 
> This all works fine, for all processes created in the pas 24hrs, eg:
> andrewm  12585  1130  0 09:19 pts/5    00:00:00 telnet lion
> 
> but fails on older processes, eg:
> andrewm   4195  1098  0 Sep 21 pts/1    00:00:00 telnet lion
> 
> apart from creating a hugely complicated regex that will catch all
> occurences, what else can I do?
> 

IMHO, there is nothing bad about using ps(1) from a perl script,
and AFAIK it is the most portable way to get such information
(yes, you may parse /proc yourself - but not every OS supports /proc).

I'd suggest to use ps -o ... instead of ps -f. With -o you will be able
to ask ps(1) to output _only_ the fields you really need, in the order
you need. You will be able to avoid the header printed also.

What is even more important - all the fields that ps -o ... will print 
are _not_ allowed to contain blank characters (except for comm and args
formats - but you can make them to appear in the last column). 
Therefore a single split is all you need.

Check your system's man ps for more information. To preserve portability
take a look at ps(1) from Single Unix Specification at
http://www.opengroup.org/onlinepubs/007908799/xcu/ps.html.

For example, the following command works on Solaris, AIX and linux
and presensts an (almost) identically formatted result:

ps -u ilja -o pid= -o user= -o vsz= -o etime= -o time= -o args=

Hope this helps.
Ilja.


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

Date: Mon, 24 Sep 2001 23:41:18 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: alternatives to ps command
Message-Id: <slrn9qudvu.8ai.mgjv@martien.heliotrope.home>

On 24 Sep 2001 11:22:42 GMT,
	F. Xavier Noria <fxn@retemail.es> wrote:
> On 24 Sep 2001 03:01:03 -0700, perl misk <perlmisk@yahoo.co.uk> wrote:
> 
>: I am trying to get a process listing
> 
> You may use Proc::ProcessTable.

Hmm, interesting. I didn't know about this module. A few days ago it was
mentioned somewhere on this group that this would have been handy. It
is. Loads of different OSes supported too..

I might play a bit with it tomorrow, and see if I can extend it a bit
for Solaris.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | I used to have a Heisenbergmobile.
Commercial Dynamics Pty. Ltd.   | Every time I looked at the
NSW, Australia                  | speedometer, I got lost.


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

Date: Mon, 24 Sep 2001 11:59:40 GMT
From: "Kalle Anka" <Kalle Anka@markisspecialisten.com>
Subject: As simply as I can put it..
Message-Id: <MeFr7.3207$aM.135472@newsc.telia.net>

$filename is a file where the e-meil addresses are stored.
$email is the "stand in" from a form, where you can type your address to get
it removed.
Im using "use strict" in my script.
Im letting my visitors to delete their e-meil addresses from my list.
The e-mail addresses are written like this:
karl@kalles.se<br>
kalle@kalles.se<br>

The big Q is how to delete the address line in $filename only if you match
all the letters, not just the first ones.


open (INFILE, "$filename") or die "Haha.': $!";

my $line;
  while (<INFILE>) {
    chomp; # drops trailing newlines; can omit if undesirable
    $line = $_, last if /^\Q$email/i && ! /^$/; # substr match!
  }

  close INFILE;
  print "Your e-mail address is now deleted from our list.<br>\n\n" if
defined $line;

  print "Your e-mail address do not exist in our list.<br>\n\n" unless
defined $line;




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

Date: Mon, 24 Sep 2001 14:28:17 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: As simply as I can put it..
Message-Id: <ciguqtcgk1aktj1b1cqt5e0nq9p3m4c1vj@4ax.com>

"Kalle Anka" <Kalle Anka@markisspecialisten.com> wrote:

>The e-mail addresses are written like this:
>karl@kalles.se<br>
>kalle@kalles.se<br>

Are you squre about those "<br>"? They look impractical.
>
>The big Q is how to delete the address line in $filename only if you match
>all the letters, not just the first ones.

>my $line;
>  while (<INFILE>) {
>    chomp; # drops trailing newlines; can omit if undesirable
>    $line = $_, last if /^\Q$email/i && ! /^$/; # substr match!
>  }

You need an end anchor.

	$line = $_, last if /^\Q$email\E$/i; # substr match!

but, since you chomped, 

	$line = $_, last if $_ eq $email;

might be better. And move that test for emptyness out of the loop: $_
and $email can only be equal, and $_ empty, if $email is empty too.

-- 
	Bart.


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

Date: 24 Sep 2001 07:07:49 -0700
From: bduffy@nycap.rr.com (Brian Duffy)
Subject: Re: Best way to hide the perl source code..
Message-Id: <8382da14.0109240607.36578421@posting.google.com>

Are you an attorney or have access to one who works free/cheap??

Licenses are all well and good, until you realize the potential costs
involved in enforcing your rights.

In a perfect world, where are businessmen are honest and ethical (and
I don't have to sell my services for money to feed my family),
allowing clients to see or tinker with source would be a great thing
for everyone.

Unfortunately, we do not live in that world.

Philip Newton <pne-news-20010922@newton.digitalspace.net> wrote in message news:<0g9oqt8rf6epi63m5ksi8j941cvr5k5t55@4ax.com>...
> On Fri, 21 Sep 2001 18:06:21 -0700, Jayakumar Mundunuri
> <jkumar@atrenta.com> wrote:
> 
> > Can you suggest me what is the best way to hide perl source code?
> 
> It seems no-one has done this yet, so I'll do it:
> 
>     perldoc -q "hide the source"
> 
> Summary: Don't try. Either delete the source, or get a decent licence.
> 
> Or try to re-think your question. Why do you think you have a need to
> hide the source? If you answer that question, perhaps there will be
> other ways to solve the question without having to hide the source.
> 
> Cheers,
> Philip


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

Date: Mon, 24 Sep 2001 23:22:47 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: eval-statement fools garbage-collection ?
Message-Id: <slrn9quct7.8ai.mgjv@martien.heliotrope.home>

On Mon, 24 Sep 2001 14:12:05 +0200,
	peter pilsl <pilsl_@goldfisch.at> wrote:
> 
> Martien Verbruggen wrote:
>>> So the memory is *not* freed at the undef-statement ..
>> 
>> You don't know that. When memory is freed, it is not necessary for the
>> process to hand it back to the OS immediately, or at all. All it means
>> is that it is available to the application for subsequent requests for
>> memory.
>> 
>> On many Unix systems it is possible for programs to return memory to the
>> OS while still running (this has not always been the case on most
>> Unices), but it can only do that under certain circumstances, and it
>> most of the time as very little control over whether or not the OS gets
>> the memory back.
>> 
> 
> thnx,
> 
> Thats an interesting point. However this makes things even worse. My 
> program runs in a mod_perl-environment and if your statement is true on my 
> system, that means, that every mod_perl-script using such structures is 
> memleaking, cause it never releases the memory back to the OS unless the 
> task terminates. 

It may not release the memory back to the OS, but the freed memory is
always available to the application itslef, if it needs new memory. It
just isn't available to other processes.

> And this is why I discovered my problem: apache-webserver seemed to be 
> memleaking when running my application on it.

It is possible that on your platform, your malloc(3) or sbrk(2) calls
are slightly broken. It is possible that the Perl you are running isn't
entirely kosher. As I showed, on my platform, it seems to work ok..

> I made subsequent tests and found out, that the memory is released to the 
> OS when I "manally" delete the structure.   (see below, dest($ptr) instead 
> of undef $ptr) So I think its a problem of perl (or better: a problem of my 
> way to use perl)

Nono. If this is the case, then I'd look at a problem in Perl. But
first, I'd make sure that perl is indeed not freeing the memory at all,
instead of just not giving it back to the OS. 

Do something like this in your test program:

my $ptr={};
$#{$ptr->{big}}=5000000;
def2($ptr);
print $ptr->{test}->{func2}(5),"\n";
print `ps -o vsize,rss,args -p $$ | tail -1`;
undef $ptr;
print `ps -o vsize,rss,args -p $$ | tail -1`;
# Make sure this allocation is smaller than the previous one
$#{$ptr->{big}}=2500000;
print `ps -o vsize,rss,args -p $$ | tail -1`;

If the memory has been correctly freed, then the memory used in the last
ps output should not be much more than the first ps output (ideally, it
should be less, but we've already established that that isn't
happening).

If you find that the memory has grown, by a significant factor, then you
do have a memory leak, and you need to investigate, maybe recompile Perl
with perl's malloc instead of the system (although I doubt it's that).

> I also extended my little script to loop around the allocate-part to see if 
> the mem is reclaimed to the OS when it needs it. At least on my linux2.4.10 
> (or 2.4.9) it does not, even if the thread gets bigger than 400M and 
> swapping makes my harddisks shake.
> The same on BSD3.4.

> perl on both machines is 5.6.0, and

Ok, I just tested with a perl 5.6.0 I have here, and it leaks like a
sieve, using the eval. It is a copy of Perl that was compiled with
threading support, while the 5.6.1 copy doesn't have threading support.
I do not have a 5.6.0 without threads, or a 5.6.1 with threads, but it
looks like the problem was either fixed between 5.6.0 and 5.6.1 or it is
related to thread support. If you don't have thread support, then you
probably need to upgrade. Otherwise, you probably need to get rid of
thread support.

Oh, what the hell. I'll compile a 5.6.1 with threads, one minute.
Actually, more than one minute...

Nope. No memory leak with perl 5.6.1 with threads enabled.

While reading the Changes file, I found this:

[  8894] By: gsar                                  on 2001/02/22 19:06:18
        Log: integrate changes#6162,6163 from mainline (missing leak fixes!)
             
             fix memory leak in method call optimization (change#3768);
             made C<eval "$x->foo()"> leak
             
             fix memory leak in C<eval "BEGIN {}"> (bug in change#4579)
     Branch: maint-5.6/perl
          !> op.c

Maybe that's the one... 5.6.1 was released on 2001-Apr-08.

> is the same here. Maybe I should have a look at perl 5.6.1.

That sounds like a good option to me.

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | In the fight between you and the
Commercial Dynamics Pty. Ltd.   | world, back the world - Franz Kafka
NSW, Australia                  | 


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

Date: 24 Sep 2001 06:32:24 -0700
From: dthusma@balsasoft.com (darrin)
Subject: Re: File compression
Message-Id: <525a9ea2.0109240532.252a8bfe@posting.google.com>

Take a look at the zlib package.  The book "Mastering Algorithims w/
Perl" devotes many pages to this very subject.

Here is a small snippet of compression that I use for packets:

use Compress::Zlib ;
$compressed_string = compress($string) ;

So, its not too hard to do, just add the file stat() to determine a
file age, then compress...

Hope this helps.

Happy coding.


Darrin




"Daz" <dc_hallett@hotmail.no.spam.com> wrote in message news:<9on1jt$e7$1@pheidippides.axion.bt.co.uk>...
> Hi,
> 
> I'm new to perl and want to write a prog that reads file headers and
> compresses files older than a certain date.
> 
> Anyone have any handy code that could help?
> 
> Regards,
> D.


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

Date: Mon, 24 Sep 2001 13:37:59 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: How to remove whitespace without losing the 'real' whitespace?
Message-Id: <mlduqtsoo1vmv3ns5v10ar1rmvld3u384f@4ax.com>

Tim Heaney wrote:

>Except he probably doesn't want to lose the newline. Perhaps you mean
>
>  s/\s+/ /g; # Replace multiple spaces with a single space.
>  s/^ //;    # Remove initial space.
>  s/ $/\n/;  # Replace final space with newline.

Now try this with "                     \n". Whoops, the entire line is
gone.

That's the reason why I chose not to do s/^\s+//: because blank lines
would be wiped in their entirety.

-- 
	Bart.


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

Date: 24 Sep 2001 06:42:10 -0700
From: bduffy@nycap.rr.com (Brian Duffy)
Subject: Re: New To Perl Scripting
Message-Id: <8382da14.0109240542.6110222c@posting.google.com>

Pick up the O'Reilly Perl CD bookshelf. It is pricey, but contains
several books that you will find very useful.

TSethorial@aol.com (MN RAIDER FAN) wrote in message news:<ec692968.0109231853.13153446@posting.google.com>...
> Hello all,
> 
>      I am a bit new to Perl Scripting, I have some experience in C++
> and Java Scripting and Visual Basic and I am wondering if I could get
> some suggestions from programmers that have worked with Perl on what
> books to pick up that will help me pick up the language quickly.
> 
> TS


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

Date: Mon, 24 Sep 2001 15:29:36 +0200
From: Andrey Shipsha <andrey@flyg.kth.se>
Subject: Perl script for monitoring a web page?
Message-Id: <3BAF3540.34D0444C@flyg.kth.se>

Hello,

I have no experience with Perl. However, I really want to have a script
which will monitor a web page for me and, once the contents of the web
page changed, send me a mail.

Are there any available scripts which could do this task?

Cheers,

Andrey.


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

Date: Mon, 24 Sep 2001 14:08:01 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Perl script for monitoring a web page?
Message-Id: <3baf3bbc.4419865@localhost>

On Mon, 24 Sep 2001 15:29:36 +0200, Andrey Shipsha
<andrey@flyg.kth.se> wrote:

>Hello,
>
>I have no experience with Perl. However, I really want to have a script
>which will monitor a web page for me and, once the contents of the web
>page changed, send me a mail.
>
>Are there any available scripts which could do this task?

Probably.  

One can be knocked out trivially with a couple of modules.  Notably:
LWP::Simple (to get the page), Net::SMTP (to send the mail) and
Digest::MD5 (to boil the page down to a small string for comparison,
you can use CRC's or direct comparison if you want to also).

Read the page
Get the MD5 signature, store this
Loop forever
      sleep a while
      Read the page
      Compute the MD5 signature of this new page
      Compare this MD5 signature to the old one if they don't match
             send the mail message
             replace the stored MD5 signature with the new one
end of loop

Implementation is left as an exercise.
    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary 
"If you rush a Miracle Man,     for details, see http://geeksalad.org
        you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Mon, 24 Sep 2001 14:44:39 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Perl script for monitoring a web page?
Message-Id: <pqguqt86t9d8ciiofqd9ggq08sssko84q5@4ax.com>

Clinton A. Pierce wrote:

>On Mon, 24 Sep 2001 15:29:36 +0200, Andrey Shipsha
><andrey@flyg.kth.se> wrote:

>>I have no experience with Perl. However, I really want to have a script
>>which will monitor a web page for me and, once the contents of the web
>>page changed, send me a mail.

The first thing I'd check out is the modification date, from the HTTP
headers.

>One can be knocked out trivially with a couple of modules.  Notably:
>LWP::Simple (to get the page), Net::SMTP (to send the mail) and
>Digest::MD5 (to boil the page down to a small string for comparison,
>you can use CRC's or direct comparison if you want to also).

Mime::Lite can be used for mail, too. IMO it's easier to use than
Net::SMTP, even when you don't want MIME mail. It's built to make use of
Net::SMTP, or one of various other mailers, if you like.

I agree with the rest of your recommendations, wholeheartedly. Er... is
there a way to get the HTTP headers from LWP, preferably LWP::Simple?
Ah, yes: head() will do. Lovely. Hmm... mirror() looks interesting too.
It does the same kind of check the OP wants, except that it downloads
the page instead of sending mail. Well, it returns a "has not been
modified" flag, so it could well be done. But since not all "dynamic
homepages" send back the last-modified header, I'd still do a
Digest::MD5 check. That's where the main functionality of mirror() comes
in handy.

-- 
	Bart.


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

Date: Mon, 24 Sep 2001 14:27:13 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: Please Help with Sockets!
Message-Id: <3baf3817$1@news.umist.ac.uk>

You don't actually say what your problem is?

Anyway, there's some nasty nesting, a bugus elsif, a missing } at the end
and a bogus tilde (~) in the match - here's a rewrite - suggest you use
warnings or #!/usr/bin/perl -w

$reply = <S>;
        if ($reply =~ /^200\s+(.*)/) { # 200 Data follows = OK
                while (<S>) {
                        #print "<P>".$_;
                        ($key, $value) = /^BILL:(.*?)=(.*)/;
                        $address{$key} = $value;
                }
                close(S);
                return 1;
        } else {
                return undef;
        }

--
  Simon Oliver




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

Date: 24 Sep 2001 07:44:18 -0700
From: phil@snark.freeserve.co.uk (Phil Hibbs)
Subject: Re: Processing page between two other pages.
Message-Id: <979ae699.0109240644.2015597@posting.google.com>

phil@snark.freeserve.co.uk (Phil Hibbs) wrote in message news:<979ae699.0109210322.7532e7a4@posting.google.com>...
> You could do it by serving up a partial HTML page and relying on the
> browser to render it despite the lack of a </BODY> and </HTML> tag,
> and then when the processing is finished, send a <meta
> HTTP-EQUIV="Refresh"...> tag that shows the results.

Sorry, I think the "Refresh" tag goes in between the </BODY> and
</HTML> tag, at least I've seen it put there.

Phil Hibbs.


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

Date: Mon, 24 Sep 2001 14:13:23 GMT
From: clintp@geeksalad.org (Clinton A. Pierce)
Subject: Re: Q: How to "reserve" processes
Message-Id: <3baf3dae.4917651@localhost>

On Mon, 24 Sep 2001 13:26:30 +0200, "Heiko Rau"
<heiko.rau@spamshield.t-systems.de> wrote:

>Hi all,
>
>with UNIX, each user has a limited amount of processes. Although this number
>is fairly high (something around 250 on the platform used) a user managed to
>start so many processes, that my perl programm (while starting normally) was
>not able to execute properly: it crashed with an error message indicating
>the lack of available processes.

The correct solution, of course, is to raise the system process limit
and give lower per-user process limits out to individual users.  These
aren't hard things to do, but usually require a reboot to take effect.

Doing what you propose is a bad idea because it needlessly uses system
resources and could jeopardize the system's reliability.  For example,
if you grab all of the process slots and someone wants to log in,
telnetd/sshd/getty can't create a new process to get the user logged
in -- you've effectively locked everyone out.  Even if you do this
only for your own user ID (the system/user proc limits are different)
you're still causing havoc it's just more limited.

Fix the problem correctly.

    Clinton A. Pierce              Teach Yourself Perl in 24 Hours  *and*
  clintp@geeksalad.org         Perl Developer's Dictionary 
"If you rush a Miracle Man,     for details, see http://geeksalad.org
        you get rotten Miracles." --Miracle Max, The Princess Bride


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

Date: Mon, 24 Sep 2001 14:39:36 GMT
From: Bob Walton <bwalton@rochester.rr.com>
Subject: Re: sub key index sorting
Message-Id: <3BAF44E3.D6A0ECC4@rochester.rr.com>

Scott Wessels wrote:
> 
> I was wondering if I might improve upon a sort routine for the following
> data structure:
 ...
> I've append to the end of this post, my current attempts at this sort, and
> presently the sprintf routine beats the others out by over two-fold though I
> have concerns that it
> may not be the most efficient of routines.
 ...
> Scott
 ...

Well, you might check it on various platforms before you make
conclusions about the algorithms, as on my computer, the ref method won:

D:\junk>perl junk87.pl
Benchmark: timing 5 iterations of ref, simple, sprintf...
       ref: 30 wallclock secs (29.72 usr +  0.00 sys = 29.72 CPU) @ 
0.17/s (n=5
)
    simple: 39 wallclock secs (38.94 usr +  0.00 sys = 38.94 CPU) @ 
0.13/s (n=5
)
   sprintf: 35 wallclock secs (35.59 usr +  0.00 sys = 35.59 CPU) @ 
0.14/s (n=5
)
        s/iter  simple sprintf     ref
simple    7.79      --     -9%    -24%
sprintf   7.12      9%      --    -16%
ref       5.94     31%     20%      --

D:\junk>perl -v

This is perl, v5.6.1 built for MSWin32-x86-multi-thread
(with 1 registered patch, see perl -V for more detail)

Copyright 1987-2001, Larry Wall

Binary build 629 provided by ActiveState Tool Corp.
http://www.ActiveState.com
Built 12:27:04 Aug 20 2001

Computer:  Windoze 98SE, 1GHz Athlon, 512 Mb RAM.
-- 
Bob Walton


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

Date: Mon, 24 Sep 2001 23:33:51 +1000
From: "aL" <nobody@nowhere.com>
Subject: The joys of segmentation faults
Message-Id: <9oncnd$3bd$1@perki.connect.com.au>

Evening all,

I've been programming in Perl for a while now, but have only just come
across the evil that is "segmentation faults". Unfortunately, it seems
documentation on this topic is somewhat lacking, so I was hoping this
newsgroup could fill me in.

With my very limited knowledge of programming principles, I know that
segmentation faults are caused by memory allocation problems (?) and that
since Perl's in-built, automatic memory management means that my code never
directly allocates / manipulates memory blocks, in theory badly written Perl
code should not be able to generate these errors (?).

So my questions are:
1) In broad terms, what causes segmentation faults under Perl? Why do they
crop up in code that generates no syntax errors and only small (i.e.
uninitialised variables, etc) -w warnings?
2) *Can* badly written Perl code cause segmentation faults?
3) How do I go about tracking down what is actually causing the fault? After
all, I don't even know what I should be looking for. Should I be looking for
anything in particular in the -w warnings? What are the common segmentation
fault causing traps?

Thanks

aL




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

Date: 24 Sep 2001 17:55:42 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: The joys of segmentation faults
Message-Id: <874rpsg0bl.fsf@abra.ru>

>>>>> On Mon, 24 Sep 2001 23:33:51 +1000, "aL" <nobody@nowhere.com> said:

a> Evening all,
a> I've been programming in Perl for a while now, but have only just come
a> across the evil that is "segmentation faults". Unfortunately, it seems
a> documentation on this topic is somewhat lacking, so I was hoping this
a> newsgroup could fill me in.

a> With my very limited knowledge of programming principles, I know that
a> segmentation faults are caused by memory allocation problems (?) and that
a> since Perl's in-built, automatic memory management means that my code never
a> directly allocates / manipulates memory blocks, in theory badly written Perl
a> code should not be able to generate these errors (?).

a> So my questions are:
a> 1) In broad terms, what causes segmentation faults under Perl? Why do they
a> crop up in code that generates no syntax errors and only small (i.e.
a> uninitialised variables, etc) -w warnings?
a> 2) *Can* badly written Perl code cause segmentation faults?
a> 3) How do I go about tracking down what is actually causing the fault? After
a> all, I don't even know what I should be looking for. Should I be looking for
a> anything in particular in the -w warnings? What are the common segmentation
a> fault causing traps?

Normally badly written Perl should not be cause segmentation faults
itself.  If you see segfault it is either:

1) Perl bug - AFAIK there was some bugs in 5.6.0 and older releases
   (however I'm don't know if 5.6.1 has known bugs which cause
   segfault).

2) It could be a bug in libraries against which Perl is linked.

3) Some Perl extensions written in C could have bug and cause segfault
   if you are using them. I remeber I had headache some time ago with
   one such bug in DBD::Pg. Probably this is most often cause of segfaults.

How can track down cause? Sorry I can offer just some ideas. If you
had a working version of your program try to find what exact changes
introduced segfault. Have you added new 'use SomeModule'? If you did
it is it written in C? If so probably it is causes segfault.


-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: 24 Sep 2001 17:59:00 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: The joys of segmentation faults
Message-Id: <87zo7kelln.fsf@abra.ru>

>>>>> On 24 Sep 2001 17:55:42 +0400, Ilya Martynov <ilya@martynov.org> said:

IM> [..skip..]

IM> Normally badly written Perl should not be cause segmentation faults
IM> itself.  If you see segfault it is either:

IM> 1) Perl bug - AFAIK there was some bugs in 5.6.0 and older releases
IM>    (however I'm don't know if 5.6.1 has known bugs which cause
IM>    segfault).

IM> 2) It could be a bug in libraries against which Perl is linked.

IM> 3) Some Perl extensions written in C could have bug and cause segfault
IM>    if you are using them. I remeber I had headache some time ago with
IM>    one such bug in DBD::Pg. Probably this is most often cause of segfaults.

Forgot

4) You OS is configured to limit available memory for processes. In
   this case if Perl tries to allocate memory and can't get it Perl
   dies with segfault.

IM> [..skip..]




-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Mon, 24 Sep 2001 23:51:58 +1000
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: threads
Message-Id: <slrn9queju.8ai.mgjv@martien.heliotrope.home>

On 24 Sep 2001 13:06:31 +0200,
	Buchleitner Martin <buchi.martin@web.de> wrote:
> Hi !
> 
> 
> 
> I am reading data from a web-server.
> but i want also to be able to send data.
> 
> 
> the reading process is a never-ending process.
> so i have to use threads.

No, you don't. You could spawn children to deal with that.

> i have a sub called readData( $readingURL ) and a
> sub called sendData( $sendingURL, $message ).

I'm a bit afraid that that is not nearly enough information to design a
piece of software.

So far, I am guessing that you have one client application that needs to
read from and write to a web server simultaneously. There's only ever
one reader and one writer? And what determines what's being read and
what's being written? if the reader triggers the writes, maybe a fork
would do? Or if the writer triggers the read (less likely) maybe a fork
would do as well. Do these readers and writers need to communicate with
each other?

Many, many questions that need to be answered before you can even design
how you want to implement your software.

> now i want to use threads to handle my problem.
> the user should be able to send data to the server
> while the program is still reading from the server.
> how may i do this?

If you insist that you want to use threads, then you should familiarize
yourself with thread programming, make sure you have a Perl that can
deal with threads, and use them.

> i read the perldoc perlthrtut but i am not sure
> what i sould do now.

perlthrtut is hardly an extensive tutorial on how threads work, and how
to use them. BTW, did you notice the first paragraph in the DESCRIPTION
section?  Threading is experimental. It's different in the ActiveState
distros from the standard distribution (Threads.pm, have you read its
documentation?). I have not used threads in Perl, simply because it is
not ready for production work yet.

Have you had a look at perlipc to see what sorts of interprocess
communication you could use?

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | 
Commercial Dynamics Pty. Ltd.   | What's another word for Thesaurus?
NSW, Australia                  | 


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

Date: Mon, 24 Sep 2001 07:53:45 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <3BAF2CD9.7B038F33@home.com>

Bart Lateur wrote:
> 
> I don't see the point for using hyphens for "named parameters"
> for subroutines. Although it doesn't prevent bareword quoting on
> the left side of a "=>", it doesn't appear to add anything else.
> So what are they good for?

My feeling has always been that it's a carryover from working in the
shell. It makes named parameters look more like command line switches.

On the other hand, maybe it goes back to when buitins wouldn't
autoquote. Was there ever a time when '-time => 1' would parse nicely
but 'time => 1' wouldn't? 

-mjc


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

Date: 24 Sep 2001 17:41:27 +0400
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <878zf4g0zc.fsf@abra.ru>

>>>>> On Mon, 24 Sep 2001 07:53:45 -0500, Michael Carman <mjcarman@home.com> said:

MC> Bart Lateur wrote:
>> 
>> I don't see the point for using hyphens for "named parameters"
>> for subroutines. Although it doesn't prevent bareword quoting on
>> the left side of a "=>", it doesn't appear to add anything else.
>> So what are they good for?

MC> My feeling has always been that it's a carryover from working in the
MC> shell. It makes named parameters look more like command line switches.

MC> On the other hand, maybe it goes back to when buitins wouldn't
MC> autoquote. Was there ever a time when '-time => 1' would parse nicely
MC> but 'time => 1' wouldn't? 

My feeling is that it was borrowed from Tk. I never wrote single line
for it but I've noticed several time hyphen used for named params in
Tk programs.

-- 
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/)                                    |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80  E4AE BE1A 53EB 323B DEE6 |
| AGAVA Software Company (http://www.agava.com/)                          |
 -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-


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

Date: Mon, 24 Sep 2001 14:57:53 +0100
From: "Simon Oliver" <simon.oliver@umist.ac.uk>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <3baf3f5b$1@news.umist.ac.uk>

> $VAR1 = '-chr';
> $VAR2 = 33;
>
> print Dumper -chr , 33
> -->
> Argument "@" isn't numeric in negation (-) at test.pl line 4.
This error is because -chr is being taken as a paramter of print not Dumper.

And to use bare quoting you must use the => notation:

print Dumper(-chr=>33);

$VAR1 = '-chr';
$VAR2 = 33;

--
  Simon Oliver




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

Date: Mon, 24 Sep 2001 14:24:18 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: What good is the hyphen for named parameters?
Message-Id: <adguqt8sgnt27m9mi7k8geqkj7bh1oqfk3@4ax.com>

Simon Oliver wrote:

>> print Dumper -chr , 33
>> -->
>> Argument "@" isn't numeric in negation (-) at test.pl line 4.
>This error is because -chr is being taken as a paramter of print not Dumper.

	print Dumper(-chr, 33);
-->
	Argument "@" isn't numeric in negation (-) at test.pl line 3.

It doesn't seem to make a difference.

>And to use bare quoting you must use the => notation:
>
>print Dumper(-chr=>33);
>
>$VAR1 = '-chr';
>$VAR2 = 33;

But that works just as well with

	print Dumper(chr=>33);
-->
	$VAR1 = 'chr';
	$VAR2 = 33;

So what's the gain?

-- 
	Bart.


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

Date: Mon, 24 Sep 2001 09:07:01 -0400
From: Peter Korman <peter_korman@lotus.com>
Subject: Re: win32 stat in directory with 4682 files
Message-Id: <3BAF2FF5.78A41E57@lotus.com>

Hi Benjamin,

Benjamin Goldberg wrote:

> > My feeling is that I should be able to do all the stats in
> > less time than it takes dos to complete a 'dir /b /s' on the same
> > directory tree.
>
> And how long is that?
>

about 10 Seconds for a uncached dir using:

g:
cd  \ENGLISH\WIN2000\ADV_SERV\I386
dir > e:\temp\x.junk

> Aha, yup you are doing this recursively.

Yes. I recursively descend. But I'm not using File::Find.
I don't have trouble with the recursive decent part.
That part coded directly long before I knew about
File::Find. I didn't want to confuse issue so I isolated
the stat in my code sample.


> The reason I think that stating the filehandle might be faster than
> stating the filename, is that it's possible [I'm not sure, since I don't
> know much if anything about Win32 internals] that when you open a file,
> it's stat structure is all pulled off of disk and put into memory
> somewhere, so stating the filehandle might get it from memory, and
> stating the filename might get it off of disk again.

It gets even curiouser than that. The combination of:

open(handle, filename);
stat(handle);

is faster than:

stat(filename);

by itself.

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

use cwd;
@when=localtime();
print $when[2], ":" , $when[1],  ":" , $when[0];
chdir "G:/ENGLISH/WIN2000/ADV_SERV/I386" || die "cant open
G:/ENGLISH/WIN2000/ADV_SERV/I386\n";
opendir D, "." || die "cant open .\n";
while (defined(my $i = readdir D))
{
   $i=join ("./", $i);
  open ($f, $i) || next;
  stat( $f, $attrib );
  close $f;
  $cnt++;
  if (0 == $cnt %200)
  {
     print ".";
     $blk++;
     if (0 == $blk % 80)
     {
       print "\n";
     }
  }
}
@when=localtime();
print $when[2], ":" , $when[1],  ":" , $when[0];
-------------------------------------------------------------------------------

Produces:

8:46:53.......................8:47:47

That is odd. No?

54 seconds to open filename and stat handle, 81 seconds to stat filename.

> > Win32::File has only 2 methods documented in the ActiveState
> > distribution:
> >
> > GetAttributes(filename, returnedAttributes)
> > SetAttributes (filename, newAttributes)
>
> How does the speed of GetAttributes compare to stat ?

Good question. Here's the answer:
-------------------------------------------------------------------------
use Win32::File qw(GetAttributes SetAttributes ARCHIVE);
@when=localtime();
print $when[2], ":" , $when[1],  ":" , $when[0];
chdir "G:/ENGLISH/WIN2000/ADV_SERV/I386" || die "cant open
G:/ENGLISH/WIN2000/ADV_SERV/I386\n";
opendir D, "." || die "cant open .\n";
while (defined(my $i = readdir D))
{
  GetAttributes( join ("./", $i), $attrib );
  $cnt++;
  if (0 == $cnt %200)
  {
     print ".";
     $blk++;
     if (0 == $blk % 80)
     {
       print "\n";
     }
  }
}
@when=localtime();
print $when[2], ":" , $when[1],  ":" , $when[0];
-----------------------------------------------------------

The snippet above produces:

8:0:15.......................8:0:45

So, 30 seconds versus 81 seconds on the same directory.
A good improvement. It's probably the best I can do in
a clean fasion, If all I want is a directory printout.

The trouble with relying on the DOS call to do a directory
is that there is no single call to DIR that will give you
ALL the files in the directory including HIDDEN and SYSTEM
files. That's why I went to perl for the directory list task
in the first place.

> If "dir" is running faster than the fastest perl code you can write, see
> if you can learn how it does it.

That would be interesting reading.

Thanks for your ideas.

Cheers,

--JPK




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

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


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