[11198] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 4798 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Feb 1 14:07:16 1999

Date: Mon, 1 Feb 99 11:00:22 -0800
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Mon, 1 Feb 1999     Volume: 8 Number: 4798

Today's topics:
    Re: Can't compile 5.005_02 under Linux.. (Greg Ward)
    Re: CGI/PERL execution problem, GRAVE <debot@xs4all.nl>
    Re: CGI/PERL execution problem, GRAVE (Bart Lateur)
    Re: Comments in Perl code <design@raincloud-studios.com>
        debug this script please <elst.fels@nospam.ping.be>
    Re: debug this script please (Steve Linberg)
    Re: Help building regex needed (Abigail)
        help please, trying to sort a multidimensional array <23_skidoo@geocities.com>
        Help Using Perl to Sendmail <achen@spsu.edu>
    Re: How does 'mail' program works (Stephen J. Tremblett)
    Re: How to do query in a list? (William D. Reardon)
    Re: How to do query in a list? (Bart Lateur)
        How to read pass varibles to a perl script from command (Steve Hedlund)
    Re: How to read pass varibles to a perl script from com <ludlow@us.ibm.com>
    Re: Is there a way to check if a called subroutine actu <ra1593@email.sps.mot.com>
    Re: Match first character of string? (Abigail)
        Multi-Processing a Large Task - Critique Req. dg50@daimlerchrysler.com
    Re: ok please don't shoot me for this question <jeff_kerrigan@hotmail.com>
    Re: ok please don't shoot me for this question <jeff_kerrigan@hotmail.com>
    Re: ok please don't shoot me for this question <jeff_kerrigan@hotmail.com>
    Re: OO Perl: Contained objects (Greg Ward)
        Problem generating a chart in perl <matthu@videotron.ca>
    Re: Problem generating a chart in perl (Greg Ward)
    Re: regex lib or Perl linked in? (Greg Ward)
    Re: Variables on right hand of s/// don't evaluate afte vertreko@my-dejanews.com
        Wanted part-time/offsite Perl programmer <zafir@codeguru.com>
        Win32 and $_ <paullyb8@fnol.net>
    Re: Writing my own Email script but not getting it. <james@xch.nospam.net>
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: 1 Feb 1999 18:18:16 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: Can't compile 5.005_02 under Linux..
Message-Id: <794r58$gea$1@news0-alterdial.uu.net>

Bob Laflamme <rlaflamm@sscinc.com> wrote:
> When the try.c program is compiled to test the compiler, the linker reports
> that it cannot find -lgdbm and the system crashes.
> I've tried all kinds of switches, looked at all the man pages for both gcc
> and ld, to no avail.
> Can someone shed some light on this for me?

Yeah, you probably don't have GDBM (the GNU version of the venerable
Unix dbm/ndbm libraries) installed.  Double check by looking for
/usr/lib/libgdbm.a and /usr/include/gdbm.h.  If not there, then you
should either 1) delete -lgdbm from the list of libraries Perl wants, or
2) install GDBM.  The latter is recommended, as having a dbm library of
some sort is really a good idea when hacking Perl (especially if you
plan to use other people's scripts or modules), and GDBM is -- I think
-- the only dbm available for Linux.

GDBM really should be included with your Linux distribution; perhaps
it's an optional package that you didn't install -- you'll have to do
whatever you do to add packages to a Caldera system.  If all else fails,
you should be able to find an RPM at ftp.redhat.com (or any mirror) --
Caldera does use RPM, doesn't it? -- or the source at ftp.gnu.org (or
any mirror).

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Mon, 01 Feb 1999 18:57:04 +0100
From: Frank de Bot <debot@xs4all.nl>
Subject: Re: CGI/PERL execution problem, GRAVE
Message-Id: <36B5EAEF.B1B82C01@xs4all.nl>

It could be you've forgot a " somewhere. (Where is always a surprise).
You have to check every line of perl. Maybe this (untested) scripts
could help:
#!/usr/bin/perl/

print "content-type: text/html\n\n";
print "Checking.....";

open (FILE, "double.pl");
@file = <FILE>;
close (FILE);

$number = 0;
foreach $line(@file) {
    $number++;
    $count = 0;
    if ($line =~ /\"/) {
  $count++;
  $line =~ s/ "/X/g;
  if ($line =~ /\"/) {
   $count++;
  }
 }


    print "Line: $number - $count<br>\n";
}

BUT, it only works if have left spacing like this: print    "Hi";   not:
print"Hi";

"Rigine Leconte" wrote:

> Apache send me :
> "Premature end of script Header"
> when i trie to execute a script cgi whith PERL
>
> My configuration :
> Version de PERL :
> =================
>
> This is perl, version 5.004_01
> Apache/1.3.2
> Linux
> CGI/1.1
> HTTP/1.0
>
> Files permissions : 755
>
> Can you help me.
> Thanks .

--
Hi, this piece is put automaticly under every mail from me.

Contact me: debot@xs4all.nl
Visit my page:  http://www.debot.nl/
    http://www.geocities.com/SunsetStrip/Frontrow/4346/top50index.html

I've much more homepage. You can just ask for them if you want.

Well, more I havn't to say, so have a nice day :-)




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

Date: Mon, 01 Feb 1999 18:26:46 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: CGI/PERL execution problem, GRAVE
Message-Id: <36b9f14a.1549269@news.skynet.be>

Rigine Leconte wrote:

>Apache send me :
>"Premature end of script Header"
>when i trie to execute a script cgi whith PERL

This will very often (unless you're stupid enough to forget to print out
the "content-type header) indicate that there's a syntax error.

Trying to send the error messages to the browser is a good approach.
This has been delt with a lot, so maybe search Dejanews. Or the FAQ (?).
Or do the search on www.perl.com .

	Bart.


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

Date: 1 Feb 1999 17:44:00 GMT
From: "Charles R. Thompson" <design@raincloud-studios.com>
Subject: Re: Comments in Perl code
Message-Id: <794p50$3ei@bgtnsc01.worldnet.att.net>

>I've been wondering about this a bit myself, today. I'd expect
a
>one-time SLIGHT slowdown, mainly due to the reading in of the
source
>file, which got a bit bigger, thus took longer to read.

This is probably total ignorance on my part, but I too don't
worry about the parser as much as I worry about the combined
filesizes of a main CGI script, modules, databases, and
libraries in a multiuser situation.

I mean... maybe I misunderstand this... but isn't there a bit of
a server performance difference where memory is an issue when
you are opening about 137,000 bytes of files with comments
compared with 98,000 bytes without when you have about 65+ users
accessing the system at the same time? Unix servers are fast and
rule the natural universe, but geez, *everything* has to have
some breaking point, or at least a downward curve.

We mainly develop for small businesses on virtual servers, so
there you already have 20 to 30 sites on the same machine, plus
there are usually CPU time limits, bandwidth issues, etc... We
have to consider every last thing imaginable to get the most out
of the machines. There is no telling what these other users are
doing on their part of the server, so we shoot for 'less is
more' in scripting. heck... I'm even so paranoid of it all that
I do stuff like this...

$CGI_PATH=$BASE_PATH.'cgi-bin/';

instead of this...

$CGI_PATH = $BASE_PATH . 'cgi-bin/';

I've found code in the past where the previous developer placed
anywhere from 3-20(yeah 20) lines of comments every 3 or so
lines of code. Worse... instead of external documentation, they
put every last lovin instruction in the script. The parser only
reads the first character... but it has to open the file to do
so in the first place.

We develop on a local Linux machine and that emulates the server
we are to install on. Before it goes up, we generally have all
the kinks worked out... so our code is parsed before upload. We
remove comments and blank lines for the sheer reason of
conserving filesize. What difference it makes is probably
useless in a single user situation, but I gotta think it makes a
fairly signifigent difference for the end users when the server
gets a flood of activity. IMO, the end users are the important
part of the equation because customers + speedy commerce site =
$ for client.

>I also wonder if the extensive use of lots of (tiny) modules
wouldn't
>have a worse effect (exporter, autoload, ...).


Depending on the Module in question, we will often install our
own versions and rip out what we don't need for the same reasons
described above. I realize alot of purists are cringing at that
thought, but for us the system works. We just started replacing
our libraries with Perl modules and often have to install our
own versions simply because the hosting service doesn't desire
to use 'cutting edge' (= new, untested on their part) versions
of modules for security purposes, which is understandable.

C 'Paranoid' T




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

Date: Mon, 1 Feb 1999 19:28:07 +0100
From: "myname@mydomain.com" <elst.fels@nospam.ping.be>
Subject: debug this script please
Message-Id: <794rk2$6k5$1@news3.Belgium.EU.net>

Can anyone tell me what is wrong with this script ?
I really don't get it, I always get an internal server error.
I chmod te files read/write/execute

Please help,

Peter

netket@dma.be

#!/usr/bin/perl -w
use strict;
srand;
my $whichImg = rand(4);
my $img;
if ($whichImg < 1)

$img = '1.gif';
}
elsif ($whichImg < 2)

$img = '2.gif';
}
elsif ($whichImg < 4)

$img = '3.gif';
}
print "<img src=\"$img\">\n";







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

Date: Mon, 01 Feb 1999 13:54:31 -0500
From: linberg@literacy.upenn.edu (Steve Linberg)
Subject: Re: debug this script please
Message-Id: <linberg-0102991354310001@ltl1.literacy.upenn.edu>

In article <794rk2$6k5$1@news3.Belgium.EU.net>, "myname@mydomain.com"
<elst.fels@nospam.ping.be> wrote:

> Can anyone tell me what is wrong with this script ?

why not do this:

perl -c 'foo.pl'

That will tell you exactly what's wrong.  You could even add "use
diagnostics" for a more verbose explanation.

-- 
Steve Linberg, Systems Programmer &c.
National Center on Adult Literacy, University of Pennsylvania
email: <linberg@literacy.upenn.edu>
WWW: <http://www.literacyonline.org>


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

Date: 1 Feb 1999 17:03:39 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Help building regex needed
Message-Id: <794mpb$qh8$1@client2.news.psi.net>

Derek Fountain (derek@fortstar.demon.co.uk) wrote on MCMLXXX September
MCMXCIII in <URL:news:36B58D6D.9C42132C@fortstar.demon.co.uk>:
|| 
||   (\w+)\s*\(             # $1 gives me the function name
|| 
|| That's good enough for what I need, but, it picks out ifs, whiles and
|| dos as well as the functions. Is it possible to say \w+ except when its
|| an i-f or w-h-i-l-e etc?

   /\b(?!(?:while|if|do)\b)(\w+)\s*\(/;



Abigail
-- 
%0=map{reverse+chop,$_}ABC,ACB,BAC,BCA,CAB,CBA;$_=shift().AC;1while+s/(\d+)((.)
(.))/($0=$1-1)?"$0$3$0{$2}1$2$0$0{$2}$4":"$3 => $4\n"/xeg;print#Towers of Hanoi


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

Date: Mon, 01 Feb 1999 17:16:57 +0000
From: 23_skidoo <23_skidoo@geocities.com>
Subject: help please, trying to sort a multidimensional array
Message-Id: <36B5E16A.64F8@geocities.com>

hi,

i'm trying to sort a 2 dimensional array. i have a setup where i have a
number of arrays, the first element of which is a number. these arrays
are stored in an array and it's this that i want to sort numerically by
the first element in the secondary array.

eg, the script generates @newsarray such that:

$newsarray[0][0] = 15;
$newsarray[1][0] = 12;
$newsarray[2][0] = 8;

i allready have the numerical sort subroutine which i use elsewhere like
this:

@killfile = sort numerically (@killfile);

sub numerically { $a <=> $b }

i'm just not sure how to carry that forward to sort the 2d array.

i did rtfaq, found this example but i don't understand the final line in
it. i added comments stating what i thought was going on.

@idx = ();  #clears the array @idx
for (@data) { 	#loops through each item in @data
	($item) = /\d+\s*(\S+)/; 
            #defines a variable '$item' which is a number of non 
            #whitespace characters located after 1 or more digits 
            #and 0 or more whitespace characters
	push @idx, uc($item); 
            #pushes an upper case version of $item into @idx
}
@sorted = @data[ sort { $idx[$a] cmp $idx[$b] } 0 .. $#idx ];
			#i got a bit lost here.

i know that {$idx[$a] cmp $idx[$b]} is comparing ascii values just like
{$idx[$a] <=> $idx[$b]} would be for a numerical sort but i'm not sure
about the square brackets and the 0 .. $#idx at the end. can anyone help
me out here?

thanks

-23


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

Date: Mon, 1 Feb 1999 12:50:20 -0500
From: "Albert Chen" <achen@spsu.edu>
Subject: Help Using Perl to Sendmail
Message-Id: <794pde$q8s$1@news-int.gatech.edu>

    I'm quite new to Perl.  I have to create an executable using perl to
send mail (not to use the "sendmail" command).
I have found a lot of scripts out on the web that claims the script will
execute without problems.  I just downloaded ActiveState's ActivePerl build
509.  I used the ppm to install a few modules (net-bind, net-dns, net-ping,
net-telnet, win32-api, libwin32, libnet, mail-pop3client, mime-lite,
mime-tools, mailtools) not knowing which modules are needed to accomplish my
objective.
    I am using one of the following script:
---------------------------Start of Script---------------------------
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

---------------------------End of Script---------------------------
    I use Windows NT 4.0 Workstation and executed the script within command
prompt:
test5.pl

The output it gave was:
Global symbol "%NetConfig" requires explicit package name at
C:\Perl\lib/Net/SMTP.pm line
29.
Compilation failed in require at C:\Perl\test5.pl line 2.
BEGIN failed--compilation aborted at C:\Perl\test5.pl line 2.

    I have searched the web for any information about the error
"%NetConfig..." and am unsuccessful in determining the solution.  Also, I am
not sure which lines I should be editing to input my information such as:
hostname, send to, sent from, message, etc.






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

Date: 1 Feb 1999 18:47:00 GMT
From: sjt@cs.mun.ca (Stephen J. Tremblett)
Subject: Re: How does 'mail' program works
Message-Id: <794sr4$vme$1@coranto.ucs.mun.ca>

abigail@fnx.com (Abigail) writes:

>Nishant Shah (nishants@usc.edu) wrote on MCMLXXVIII September MCMXCIII in
><URL:news:Pine.GSO.4.02.9901301453470.9479-100000@nunki.usc.edu>:
>{} 
>{} Is there any 'command line' option with mail program which allows me to
>{} write the subject field.

>That's not a Perl question. Use the appropriate group for the mail
>program you are using.


The time/effort/bandwidth/oxygen you wasted in posting that comment
could just as well have been used to say 'mail -s [subject]'.  Even
funnier is that your rude enforcement of netiquette resulted in a
crosspost to comp.unix.questions.  Thus I say "That's not a UNIX
question.  Use the appropriate group for your stingy comment
(comp.dev.null)."

Have a nice day :)

--
-=> Steve Tremblett    	  
-=> Memorial University Computer Science
-=> sjt@cs.mun.ca; www.cs.mun.ca/~sjt 


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

Date: Mon, 1 Feb 1999 17:34:37 GMT
From: wdr1@pobox.com (William D. Reardon)
Subject: Re: How to do query in a list?
Message-Id: <F6HKtq.6xn@midway.uchicago.edu>

In article <MPG.111f6ca725bcc1389899ee@nntp.hpl.hp.com>,
Larry Rosler <lr@hpl.hp.com> wrote:
>
>There is a bug in this code which is so obvious that it is clear that 
>you didn't try this snippet before posting it.  (Of course, it's 
>*possible* that you did, and supplied the argument from the command line 
>in a very peculiar way -- hint, hint, for the bug -- but I rather doubt 
>it.)

Version 1.1 :) : 
#!/usr/local/bin/perl -w
$file = "computers.txt";
$computer = shift;

open(F, $file) || die("Couldn't open $file: $!");
while (<F>) {
    chomp;
    die("Found $computer\n") if ($_ eq $computer);
}

print "$computer not found", "\n";
 

>> 	grep {$computer eq $_}, @computers;
>
>Here is what the FAQ says about this:
>
><QUOTE>
>Please do not use 
>    $is_there = grep $_ eq $whatever, @array;
></QUOTE>

	True, but the reasons it gives are faulty, and it ignores that
1) grep is sometimes faster, and 2) is more succinct, yielding clearer
& easier to maintain code (IMHO).

-Bill
-- 
William Reardon	  ----   http://www.nhma.com/~wdr1/   ----   wdr1@pobox.com
       It takes 41 muscles to frown, but only 4 to pull a trigger.


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

Date: Mon, 01 Feb 1999 18:26:40 GMT
From: bart.lateur@skynet.be (Bart Lateur)
Subject: Re: How to do query in a list?
Message-Id: <36b8f003.1222246@news.skynet.be>

Larry Rosler wrote:

>> 	grep {$computer eq $_}, @computers;
>
>Here is what the FAQ says about this:
>
><QUOTE>
>Please do not use 
>    $is_there = grep $_ eq $whatever, @array;
></QUOTE>
>
>Who ya' gonna trust?

This has been discussed VERY recently on comp.lang.perl.moderated. The
"consensus" was that for relatively small lists and definitely for
one-shots, grep is acceptable. After all, a foreach loop will on average
check around half the list before the item is  found, and the whole list
if it isn't found. grep will always search the entire list, but maybe
(probably) faster per item than foreach.

Building a hash is only really yinteresting for large lists and frequent
searches in the same run. This is not the case here.

	Bart.


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

Date: Mon, 01 Feb 1999 17:33:20 GMT
From: ssh@dpn.com (Steve Hedlund)
Subject: How to read pass varibles to a perl script from command line?
Message-Id: <36b5e40a.4554623@news.lvcablemodem.com>

What want to do is say fdf.pl  var1 var2 var3 and use them in the perl
program.

Using cgi I can read varible that are passed using this

#!/usr/local/bin/perl

use Getopt::Long;

#Get information from submit
if (@ARGV) {
  foreach (@ARGV) {
($frm,$com,$brn) = split(/\\&/);
  }
}

I can get one varible using :

my $ob_19 = shift;

I can't figure out to read more than one varible.

Thanks fro the help!
Steve Hedlund 
ssh@don.com



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

Date: Mon, 01 Feb 1999 11:58:06 -0600
From: James Ludlow <ludlow@us.ibm.com>
Subject: Re: How to read pass varibles to a perl script from command line?
Message-Id: <36B5EB2E.E4B0F4A4@us.ibm.com>

Steve Hedlund wrote:

> What want to do is say fdf.pl  var1 var2 var3 and use them in the perl
> program.

> I can get one varible using :
> 
> my $ob_19 = shift;
> 
> I can't figure out to read more than one varible.

I'm sorry, I honestly can't tell if you know what the shift function
does or not.  If not, read about it first.

@ARGV is the array that holds the command line arguments sent to your
script.  Anything that Getopt doesn't eat will still be in @ARGV.  When
you're doing a shift in the context that you described, you are shifting
a value out of @ARGV.  So, if you want another value, shift again.

my $arg0 = shift;
my $arg1 = shift;
etc...

Of course, at some point doing all those shift's become a huge waste of
typing time.  You can treat @ARGV just like any other array.

my ($arg0, $arg1) = @ARGV;

I strongly suggest running a program with -d once and looking at the
values of @ARGV before and after the shift statements.  It will be very
enlightening.

$ perl -de 'print shift; print shift' foo bar

DB<1> x @ARGV
DB<1> s
DB<1> x @ARGV
DB<1> s 

-- 
James Ludlow (ludlow@us.ibm.com)
(Any opinions expressed are my own, not necessarily those of IBM)


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

Date: Mon, 01 Feb 1999 10:53:20 -0600
From: Patrick Svatek <ra1593@email.sps.mot.com>
Subject: Re: Is there a way to check if a called subroutine actually exists?
Message-Id: <36B5DC00.E8ED097C@email.sps.mot.com>

Yeah! Thanks guy! That will work..

-Pat

Jonathan Feinberg wrote:
> 
> Patrick Svatek <ra1593@email.sps.mot.com> writes:
> 
> > $var_name = $Form{'user_requested_name'};
> >
> > and then calling the sub like:
> >
> > print &$var_name;
> 
> Yerk!  Instead of "symbolic sub references", why not a
> self-documenting, easier-to-debug, friendly neighborhood hash of sub
> refs?
> 
> my %dispatch_table = (
>                        one_request     => \&one_sub,
>                        another_request => \&another_sub,
>                      );
> $name = $Form{'user_requested_name'};
> if (exists $dispatch_table{$name}) {
>    $dispatch_table{name}->();
> }
> else {
>    explode();
> }
> 
> --
> Jonathan Feinberg   jdf@pobox.com   Sunny Brooklyn, NY
> http://pobox.com/~jdf


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

Date: 1 Feb 1999 17:07:26 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: Match first character of string?
Message-Id: <794n0e$qh8$2@client2.news.psi.net>

Delphine Coupal (delphine@qx.net) wrote on MCMLXXX September MCMXCIII in
<URL:news:36B5203E.567209D4@qx.net>:
^^ What's the easiest way to match the first non-space character of
^^ a string?

  /\S/;



Abigail
-- 
perl -wle 'print "Prime" if ("m" x shift) !~ m m^\m?$|^(\m\m+?)\1+$mm'


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

Date: Mon, 01 Feb 1999 17:34:53 GMT
From: dg50@daimlerchrysler.com
Subject: Multi-Processing a Large Task - Critique Req.
Message-Id: <794ojs$7aq$1@nnrp1.dejanews.com>

Hello all,

I'm looking for some critique on this program I've written, esp. with
reference to where I could be getting into trouble with the signal handlers.
I have a program that does Open3 calls (on AIX) to read STDIN and STDERR, and
write to STDIN that's segfaulting at unpredictable intervals and I want to
avoid that behaviour here.

What the program does is this: you have a large array @my_list that contains a
list of items you wish to do actions upon (here, it's a busy loop but the
production code does LDAP searches and updates). Rather than step through each
list element in series, this forks off children and assigns them a part of the
array to work on, thus parallelizing the task and making it run faster.

Note that in this example, @my_list is forked, so that means (I think) that
each child has a copy of the @my_list data structure. For very large
@my_lists (180k elements in production) that's a LOT of wasted space - is
there a way to either share the memory, or pass only chunks of the @my_list
array? IPC::Shareable doesn't seem to allow shared arrays, only scalars and
hashes.

Tom: The Perl Cookbook is a goldmine. I'd never've been able to get this far
without it.

Program follows:
-----------------------------------------------------------------------------
--- #!/usr/bin/perl

# Forktest.pl
# A test case to see if this will work

$| = 1;

use Symbol;
use POSIX;
use IPC::Shareable;	# For sharing data across processes

###########################################################################
# Config
$chunksize = 10;
$numentries = 5000;
$family_size = 5;

###########################################################################
# Subroutines

sub REAPER {
   print "Reaping\n";
   # Clean up after our dead children
   $SIG{CHLD} = \&REAPER;
   my $pid = wait;
   $child_count--;
   delete $CHILDREN{$pid};
}#-------------------------------------------------------------------------

sub HUNTSMAN {
   print "Killing kiddies\n";
   # Explicitly murder our children if we get killed
   local($SIG{CHLD}) = 'IGNORE';
   kill 'INT' => keys %CHILDREN;
   exit;
}#-------------------------------------------------------------------------

sub PROGRESS {
   # Update the progress report
   $SIG{USR1} = \&PROGRESS;
   print ".";
   # These are shared memory varables, otherwise we get per-thread progress
   # bars
   $h1->shlock();
   $h2->shlock();
   $column++;
   $processed = $processed + $chunksize;
   if ($column > 79) {
      print "\n";
      $column = 0;
      $steptime = time();
      $deltatime = $steptime - $starttime;
      $deltatime = 1 if (! $deltatime);
      $progress_rate = $processed / $deltatime;
      $percentile = int(($processed / $numentries) * 100);
      print "$processed entries processed in $deltatime seconds\n";
      print "$percentile \% done at $progress_rate entries per second\n";
   }
   $h1->shunlock();
   $h2->shunlock();
}#-------------------------------------------------------------------------

sub busy_work {
   # Somthing for the child to do
   my ($start, $finish, $childno, $chunksize, $ppid, $data) = @_;
   my $x, $progress;

   for ($x = $start; $x < $finish; $x++) {
      #print "CHILD $childno: $data->[$x]\n";
      $progress++;
      if ($progress > $chunksize) {
         $progress = 0;
         kill 'USR1', $ppid;
         sleep 1;
      }
   }
}#-------------------------------------------------------------------------

sub procreate {
   # Create our children
   # Resisted all number of obscene names for this routine :)

   my ($start, $finish, $childno, $chunksize, $ppid, $data) = @_;
   my $pid, $sigset;

   # Block signal for fork
   $sigset = POSIX::SigSet->new(SIGINT);
   sigprocmask(SIG_BLOCK, $sigset) or die "Can't block SIGINT: $!\n";

   die "Fork: $!\n" unless defined ($pid = fork);

   if ($pid) {
      # Record a successful birth, then return
      sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT: $!\n";
      $CHILDREN{$pid} = $childno;
      $child_count++;
      return;
   }
   else {
      # We're a child!
      $SIG{INT} = 'DEFAULT';

      sigprocmask(SIG_UNBLOCK, $sigset) or die "Can't unblock SIGINT: $!\n";

      busy_work($start, $finish, $childno, $chunksize, $$, $data);

      # MUST USE EXIT - NOT RETURN!
      exit;
   }
}#-------------------------------------------------------------------------

###########################################################################
# Main

$starttime = time();
print "Parent starting\n";

# Build some data
for ($y=0; $y<$numentries; $y++) {
   $my_list[$y] = rand;
}

# Set up the shared variables $column and $processed
# Would REALLY like to share @my_list!
$h1 = tie $column, 'IPC::Shareable', undef, { destroy => 1};
$h2 = tie $processed,'IPC::Shareable', undef, { destroy => 1};

$child_chunksize = int ($numentries/$family_size);
$startpoint = 0;
$endpoint = $child_chunksize;

# Signal Handlers
$SIG{CHLD} = \&REAPER;
$SIG{INT} = \&HUNTSMAN;
$SIG{USR1} = \&PROGRESS;

# And awayyyy we go!
for ($q=0; $q<$family_size; $q++) {
   procreate($startpoint, $endpoint, $q, $chunksize, $$, \@my_list);
   $startpoint = $endpoint+1;
   $endpoint = $endpoint + $child_chunksize;
   if (($numentries - $endpoint) < $child_chunksize) {
      $endpoint = $numentries; # Youngest gets most work
   }
}

while ($child_count > 0) {
   sleep;
}

print "All done!\n";

# END
-----------------------------------------------------------------------------
---

DG

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


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

Date: Mon, 01 Feb 1999 09:48:59 -0800
From: Jeff Kerrigan <jeff_kerrigan@hotmail.com>
Subject: Re: ok please don't shoot me for this question
Message-Id: <36B5E90B.A81951FB@hotmail.com>

Point well taken

Ronald J Kimball wrote:

> Jeff Kerrigan <jeff_kerrigan@hotmail.com> wrote:
>
> > It seems like people on this channel waste more time delivering sarcastic
> > answers than the 2 seconds it takes to help out a newbie.
>
> Actually, it takes *four* seconds to help out a newbie, whereas I can
> deliver a sarcastic answer in under three seconds.
>
> > Try Matt's Scripts
> > Archive at:
> >
> > http://www.worldwidemart.com/scripts/
> >
> > It seems to be a popular place to get a lot of prewritten CGI scripts.
>
> Yes, judging from the number of people who come to clpm asking for help
> with actually getting Matt's scripts to work, Matt's Script Archive is
> depressingly popular.  Specifically, they are outdated, buggy, and
> unsupported, and they don't do such things as error checking or file
> locking.
>
> Now we'll be seeing even more newbies coming here asking for help with
> Matt's scripts, and we'll have to waste even more time delivering
> sarcastic answers.  Thank you so much.
>
> --
>  _ / '  _      /         - aka -          rjk@linguist.dartmouth.edu
> ( /)//)//)(//)/(     Ronald J Kimball      chipmunk@m-net.arbornet.org
>     /                                  http://www.ziplink.net/~rjk/
>         "It's funny 'cause it's true ... and vice versa."



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

Date: Mon, 01 Feb 1999 09:49:44 -0800
From: Jeff Kerrigan <jeff_kerrigan@hotmail.com>
Subject: Re: ok please don't shoot me for this question
Message-Id: <36B5E938.CE80733A@hotmail.com>

Point well taken

Murali Ravipudi wrote:

> How about putting up all the scripts made by people in clpm at some site
> ( if the owner is willing to share it ) , so that we can direct newbies
> there, where we know everything is mostly perfect and all that...
> :)
>
> -murali
>
> ** remove _ from address to mail
>
> Ronald J Kimball wrote:
> >
> --snip--
> >
> > Yes, judging from the number of people who come to clpm asking for help
> > with actually getting Matt's scripts to work, Matt's Script Archive is
> > depressingly popular.  Specifically, they are outdated, buggy, and
> > unsupported, and they don't do such things as error checking or file
> > locking.
>
> --snip--



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

Date: Mon, 01 Feb 1999 09:49:19 -0800
From: Jeff Kerrigan <jeff_kerrigan@hotmail.com>
Subject: Re: ok please don't shoot me for this question
Message-Id: <36B5E91F.AE068EA9@hotmail.com>

Point well taken

Eugene Sotirescu wrote:

> Jeff Kerrigan wrote:
> >
> > It seems like people on this channel waste more time delivering sarcastic
> > answers than the 2 seconds it takes to help out a newbie.  Try Matt's Scripts
> > Archive at:
> >
> > http://www.worldwidemart.com/scripts/
>
> You may be right. Thanks for helping this newbie.
> Please hang around for when the questions about this and that not
> working in Matt's scripts start coming in.
>
> --
> Eugene
>
> "Light is the all-exacting good,
> That dry, forever virile stream
> That wipes each thing to what it is,
> The whole, collage and stone, cleansed
> To its proper pastoral."
>                         Alvin Feinman



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

Date: 1 Feb 1999 18:33:34 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: OO Perl: Contained objects
Message-Id: <794s1u$i2h$1@news0-alterdial.uu.net>

Lee Mulleady <lemull@unx.sas.com> wrote:
> We have a situation where we need a child object to know information
> about its parent.  We handled this by passing the parents object
> reference to the child constructor (new) method and storing it as a
> member of the child.  This way, whenever the child object needed to
> know information about the parent it used the stored object reference
> to retrieve the information.  
> 
> The problem we are seeing is that when attempting to deconstruct the
> parent object using the undef() function, it fails to kick off the
> DESTROY() method of the parent and does not remove the parent object
> reference from memory.  This appears to be a direct result of storing
> its object reference within the child.  

Right.  That's because Perl uses reference-counting instead of "real"
garbage collection, and reference-counting breaks down with circular
references.

> Is there a standard way of handling this dilema?  Does Perl provide
> some built in functionality for a child object to retrieve information
> about its parent?

To the second question: no, that wouldn't make sense in a language as
loosely-defined and open-ended as Perl.  Sure, *you* might always code
in such a way that the "child" object is constructed by its "parent"
object, but I might prefer to code in a different way.  Perl generally
doesn't go for standardizing that sort of thing.

To the first question: dunno about "standard ways", but the usual hack
is to break the circular reference in some way.  If one or both of your
classes provides "close" or "shutdown" method, no problem: just break
the link there (eg. "undef $self->{'child'}" if in the "parent", or
"undef $self->{'parent'}" in the child).  Then reference-counting will
be able to do its thing and clean up properly.

However, if you want both of your instances to just magically go away
when they go out of scope, you'll have to add in a bit of ugliness.
Probably the easiest way is to add an explicit "close" or "shutdown"
method; that at least is more general than a "break_circular_links"
method.

I have some example code that's just a bit long to post (~60 lines);
email me if you'd like it.  It's mostly trivial though -- the key is
doing that "undef $child->{'parent'}" or similar.

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Mon, 1 Feb 1999 12:53:43 -0500
From: "Matts" <matthu@videotron.ca>
Subject: Problem generating a chart in perl
Message-Id: <QTlt2.869$f4.374@weber.videotron.net>

This is a multi-part message in MIME format.

------=_NextPart_000_0008_01BE4DE1.E607BE00
Content-Type: text/plain;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

My boss want me to generate a chart from a datafile. I know how to =
generate one that goes from left to right using a table but he wants it =
down to up. I figured a table won't work in that situation. Somebody =
told me about image generation in a CGI how can I do that? I don't know =
any language to generate an image...=20

------=_NextPart_000_0008_01BE4DE1.E607BE00
Content-Type: text/html;
	charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD W3 HTML//EN">
<HTML>
<HEAD>

<META content=3Dtext/html;charset=3Diso-8859-1 =
http-equiv=3DContent-Type>
<META content=3D'"MSHTML 4.72.3110.7"' name=3DGENERATOR>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT size=3D2>My boss want me to generate a chart from a datafile. =
I know=20
how to generate one that goes from left to right using a table but he =
wants it=20
down to up. I figured a table won't work in that situation. Somebody =
told me=20
about image generation in a CGI how can I do that? I don't know any =
language to=20
generate an image... </FONT></DIV></BODY></HTML>

------=_NextPart_000_0008_01BE4DE1.E607BE00--



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

Date: 1 Feb 1999 18:46:23 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: Problem generating a chart in perl
Message-Id: <794spv$i2h$3@news0-alterdial.uu.net>

Matts <matthu@videotron.ca> wrote:
> This is a multi-part message in MIME format.
                                  ^^^^
Ugh.  Please don't do that.  And especially, **please** don't post HTML
to USENET!

> My boss want me to generate a chart from a datafile. I know how to =
> generate one that goes from left to right using a table but he wants it =
> down to up. I figured a table won't work in that situation. Somebody =
> told me about image generation in a CGI how can I do that? I don't know =
> any language to generate an image...=20

Have you thought of using a spreadsheet?  Apparently the software
company that makes this "Windows" thing also produces a very popular
spreadsheet program, which I gather has many options for producing
charts and graphs.

If you're determined to write code for this -- eg. it's a task which
must be done many times from similar data files -- than Perl's probably
a good choice.  You might look into the GD library (actually, a C
library and a Perl module that interfaces to it) for creating GIF files
from Perl scripts (or C programs, for that matter).  PerlMagick, a suite
of modules that provide a Perl interface to the large and powerful
ImageMagick toolset, might also be useful.  Big tool = potentially steep
learning curve, though.

If your data files are really big, you might need the power of PDL (Perl
Data Language), which provides efficient, opaque, multidimensional
arrays to Perl.  I don't know what the state of graphing is in PDL --
hopefully they have progressed beyond interfaces to clunky FORTRAN
plotting libraries that astronomers seem to like.  ;-)

All of these things can be found on CPAN, of course.  PerlMagick will be
found under "Image::Magick"; the other two are obvious.

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: 1 Feb 1999 18:39:08 GMT
From: gward@cnri.reston.va.us (Greg Ward)
Subject: Re: regex lib or Perl linked in?
Message-Id: <794scc$i2h$2@news0-alterdial.uu.net>

jimmy <jimmy@globalSpam.org> wrote:
> Greg Ward wrote:
> > [I provide free advertising for the PCRE library, including an ftp
> >  URL that I nicked from the Python source distribution]
> 
> I looked there--it's a directory listing w/o a readme file. Where do I
> look for this regex package there?

Umm.. what's the problem?  The ftp URL I gave
(ftp://ftp.cus.cam.ac.uk/pub/software/programs/pcre/) is for a directory
that contains two files:

   pcre-1.09.tar.gz
   pcre-2.02.tar.gz

Pick one.  (PCRE 1.0 had the regular expressions of Perl 5.004, 2.0 has
5.005.)  Download it.  Unpack it.  Read the instructions.

Is there some problem here?

        Greg
-- 
Greg Ward - software developer                    gward@cnri.reston.va.us
Corporation for National Research Initiatives    
1895 Preston White Drive                      voice: +1-703-620-8990 x287
Reston, Virginia, USA  20191-5434               fax: +1-703-620-0913


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

Date: Mon, 01 Feb 1999 16:42:37 GMT
From: vertreko@my-dejanews.com
Subject: Re: Variables on right hand of s/// don't evaluate after compile time????
Message-Id: <794lhs$4r9$1@nnrp1.dejanews.com>

Wow!  Thanks, man.  I've been using Perl for over a year, and didn't realize
that substitutions done on '$_' in foreach (@array) would be written BACK into
@array.

Thanks again for the help.

In article <36B3A660.EA6001E3@home.com>,
  Phraktyl <phraktyl@home.com> wrote:
> vertreko@my-dejanews.com wrote:
> > @stuff = ("original");
> > @subs  = ("sub1","sub2");
> >
> > foreach $sub (@subs) {
> >   foreach (@stuff) {
> >     print "Trying to turn 'original' into $sub ...\n";
> >     s/original/$sub/;
> >     print "Got: $_\n";
> >   }
> > }
>
> After the first time you go through the inner foreach loop, your
> variables are:
>
> @stuff = ("sub1");
> @subs  = ("sub1", "sub2");
>
> There is not original to change.
>
> You can check this out by putting:
>
> print "Sub $sub: Stuff = @stuff\n";
>
> between the two 'foreach' lines.
>
> HTH,
> Wyatt
>

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


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

Date: 1 Feb 1999 08:50:10 -0800
From: "Zafir Anjum" <zafir@codeguru.com>
Subject: Wanted part-time/offsite Perl programmer
Message-Id: <36b5db42.0@209.66.99.126>


We are looking for a part-time Perl programmer to implement a 
number of features at our website.

Preferred skills:
1. Perl (of course)
2. CGI
3. mod_perl, Apache
4. DBI

Please send your resume to zafir@codeguru.com with the number
of hours you would be willing to work each week and your salary
expectation. 

You are welcome to apply if you don't have any job experience
(that is, if you are still in school) as long as you can 
demonstrate your skills.

Thanks,
Zafir
zafir@codeguru.com



-----------------** -- Posted from CodeGuru -- **-----------------
http://www.codeguru.com/    The website for Visual C++ programmers.



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

Date: Mon, 01 Feb 1999 13:46:21 -0500
From: Paul Bruno <paullyb8@fnol.net>
Subject: Win32 and $_
Message-Id: <36B5F67D.A44BAE5E@fnol.net>

<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
<html>
<tt>Hey, everyone!&nbsp; Ok, here's the problem:&nbsp; I am using Active
Perl, build 509, on Win95 and haven't had too many problems.</tt><tt></tt>
<p><tt>Except for this one:&nbsp; The default varible $_ just doesn't work
on my machine!!!&nbsp; For example, a script snippet like this,</tt>
<br><tt>snip| &lt;STDIN>;</tt>
<br><tt>snip| print "Here is the value of the def var:\n$_";</tt>
<br><tt>just doesn't work on my machine!!!&nbsp; Although no one really
needs the default varible, I just wanted to know what was up with this!</tt><tt></tt>
<p><tt>Thanks for the looking at the message, and for all the help, guys!</tt><tt></tt>
<p><tt>Have a good one!</tt><tt></tt>
<p><tt>Sincerely,</tt><tt></tt>
<p><tt>Paul</tt>
<br>&nbsp;</html>



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

Date: Mon, 1 Feb 1999 17:09:21 -0000
From: "James Huckle" <james@xch.nospam.net>
Subject: Re: Writing my own Email script but not getting it.
Message-Id: <36b62923.0@206.100.206.63>


Quentin Compson wrote in message <01be4b04$7142ace0$0d20440c@brmptrue>...
>Hi
>
>I'm trying learn how to write a simple script to send the results
>of a cgi form.
>It is send the subject line but ignoring the body.
>Can anyone tell me what I am doing wrong.
>
>#!/usr/bin/perl
>
>$mailprog= "/usr/sbin/sendmail" ;

sendmail -t seems to be the standard way of calling this

Once you have opened the sendmail file handle, print to it using the format
that sendmail -t knows, ie 'To: recipient@domain\n'. The newline is
important.

Have you checked your mail log?

This is standard 'read the FAQ' stuff

>
>
>$recipient= "bcompson\@yahoo.com";
>
>open(MAIL, "|$mailprog $recipient")
>    || &HTMLdie("Couldn't send the mail (couldn't run $mailprog).") ;
>$ENV{'HTTP_REFERER'} || ($ENV{'HTTP_REFERER'}= "SLC") ;
>print MAIL "Subject: Form data from the Web\n\n",
>           "The following data was entered at $ENV{'HTTP_REFERER'}:\n\n" ;
>
>
>read(STDIN, $in, $ENV{'CONTENT_LENGTH'}) ;
>
>@elements = split(/&/, $in);
>
>foreach $element (@elements) {
> $element =~ tr/+/ /;
> ($name, $value)= split("=", $element) ;
> $name =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C", hex($1))/eg;
> $value =~ s/%([\dA-Fa-f][\dA-Fa-f])/ pack ("C", hex($1))/eg;
>
>print MAIL "$name = $value",
>}

>
>close(MAIL) ;
>print <<EOF ;
>Content-type: text/html
>
><html>
><body>
><h3>Your data has been sent.</h3>
></body>
></html>
>EOF
>
>
>http://revdwj.virtualave.net/suggest3.html
>




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

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

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