[16541] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 3953 Volume: 9

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue Aug 8 18:10:47 2000

Date: Tue, 8 Aug 2000 15:10:27 -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: <965772627-v9-i3953@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Tue, 8 Aug 2000     Volume: 9 Number: 3953

Today's topics:
    Re: function like grep <tim@ipac.caltech.edu>
    Re: Gee, thanks for all the help  :-( (David H. Adler)
        Help Regex newbie colincode@my-deja.com
    Re: Help Regex newbie <care227@attglobal.net>
    Re: Help Regex newbie <russ_jones@rac.ray.com>
        How to do setuid script on Perl5.6 <delta1604@my-deja.com>
    Re: How to do setuid script on Perl5.6 <russ_jones@rac.ray.com>
    Re: How to do setuid script on Perl5.6 <care227@attglobal.net>
    Re: How to open and append to a file <timewarp@shentel.net>
    Re: How to open and append to a file <aqumsieh@hyperchip.com>
    Re: How to parse an odd file format? <mjcarman@home.com>
    Re: How to parse an odd file format? <tim@ipac.caltech.edu>
        Howto find module informations in perldoc (Otto Wyss)
    Re: Howto find module informations in perldoc <newsposter@cthulhu.demon.nl>
    Re: I need further clarity on rand() etc. <gorbeast@SPAMSUCKS.subduction.org>
    Re: I need further clarity on rand() etc. <mauldin@netstorm.net>
    Re: I need further clarity on rand() etc. <waltman@netaxs.com>
    Re: Interesection and subtraction of data sets. <aqumsieh@hyperchip.com>
    Re: Largest files <jeff@yoak.com>
    Re: Largest files <tony_curtis32@yahoo.com>
        Mail::Send Problem! kaivix@angelfire.com
        My second forking problem <T.Cockle@staffs.ac.uk>
    Re: My second forking problem <T.Cockle@staffs.ac.uk>
        Newbie questions: What exactly is $_? fathacka@my-deja.com
    Re: Newbie questions: What exactly is $_? <care227@attglobal.net>
    Re: Novice question: How to kill a process <tim@ipac.caltech.edu>
    Re: OT FS: PerlServices.com Domain Name <uri@sysarch.com>
        OT: Re: Converting from US dates/numbers to European da <juex@deja.com>
        Parse::RecDescent: @item woes <stephen@twocats.dont-spam.demon.co.uk>
    Re: Parse::RecDescent: @item woes (Damian Conway)
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Tue, 08 Aug 2000 13:39:08 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: function like grep
Message-Id: <39906FEC.2EA5E9E3@ipac.caltech.edu>

unplug wrote:
> 
> Does perl has any function like grep??

Plug in, dude:

perldoc -f grep

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: 8 Aug 2000 22:01:32 GMT
From: dha@panix.com (David H. Adler)
Subject: Re: Gee, thanks for all the help  :-(
Message-Id: <slrn8p10ps.bkq.dha@panix2.panix.com>

On Fri, 4 Aug 2000 11:24:55 +0100, Steve Jones
<steve.jones@takethisoutproact.net> wrote:

>Perl is interpreted. It doesn't have a compiler, it has an interpreter. You
>don't compile the source to binary code. Perl executes text files containing
>Perl scripts.

Just to keep the record straight, Perl is both interpreted *and*
compiled.

dha

-- 
David H. Adler - <dha@panix.com> - http://www.panix.com/~dha/
"You can lead a bigot to water, but if you don't tie him up, you can't
make him drown." - The Psychodots


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

Date: Tue, 08 Aug 2000 19:42:14 GMT
From: colincode@my-deja.com
Subject: Help Regex newbie
Message-Id: <8mpnql$dgc$1@nnrp1.deja.com>

Ok, I am having a hard time understanding regex.  I have read the
chapter on expressions from the book Effective Perl programming but I
have yet to understand how it works.

What I need to do is this.

I have a string that I need to test the first character to see if is a
particular character.

So example if the string is "Boieng" I need to test if the first
character "B" in this case, matches [a-c A-C] and then perform a
function if it does.

Any help would be appreciated

Thanks,
Colin Faulkingham



Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 08 Aug 2000 16:06:08 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Help Regex newbie
Message-Id: <39906830.E94D74C6@attglobal.net>

colincode@my-deja.com wrote:
> 
> 
> So example if the string is "Boieng" I need to test if the first
> character "B" in this case, matches [a-c A-C] and then perform a
> function if it does.
> 

Read the documentation for substr(), and then read the Perl
regex documentation...

my $string = 'Boeing';

if ( substr($string,0,1) =~ /[a-c]/i)
{
	print "I'm a letter in the range of a-c!"
}

or, without substr():

my $string = 'Boeing';

some_function if $string =~ /^[a-c]{1}.*/i


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

Date: Tue, 08 Aug 2000 15:34:27 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: Help Regex newbie
Message-Id: <39906ED3.AAB32C88@rac.ray.com>

Drew Simonis wrote:
>

<useless typical Drew twaddle snipped>

> or, without substr():
> 
> my $string = 'Boeing';
> 
> some_function if $string =~ /^[a-c]{1}.*/i

Yer confusin' me wit all dose squiggly things. How about

	... if $string =~ /^[a-c]/i

instead?

-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Tue, 08 Aug 2000 20:32:33 GMT
From: Denny Hardian <delta1604@my-deja.com>
Subject: How to do setuid script on Perl5.6
Message-Id: <8mpqp1$ff1$1@nnrp1.deja.com>

Hi Perl gurus,
  I am trying to make a setuid script on Perl 5.6 however I couldn't do
that. Perl doesn't allow me to run setuid. I compiled Perl 5.6 with
setuid emulation turned on.
  This is a test script that I used to test setuid script :
#!/dyhboc/perl5.6.0/perl
print "SETUID = $<\n";
print "SETEUID = $>\n";
{
redo;
}

This is the permission of that script :
250 [/tmp]> ls -la loop.pl
-rwsr-xr-x   1 root     system       236 Aug 08 16:27 loop.pl

And this is what I get when trying to run that script :
s11f06n09:dyhboc:/tmp>./loop.pl
Can't do setuid

Do you have any clue of what causing this error message ? I was able to
run the same script on Perl 5.00503. Please advise. Thanks.

Denny


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 08 Aug 2000 16:06:55 -0500
From: Russ Jones <russ_jones@rac.ray.com>
Subject: Re: How to do setuid script on Perl5.6
Message-Id: <3990766F.E66AD34D@rac.ray.com>

Denny Hardian wrote:
> 
> Hi Perl gurus,
>   I am trying to make a setuid script on Perl 5.6 however I couldn't do
> that. Perl doesn't allow me to run setuid. I compiled Perl 5.6 with
> setuid emulation turned on.

There's a script called "wrapsuid" in the Perl distribution that will
wrap a C program around your Perl script. The C program will be setuid
and it will then call your script, which will inherit the C program's
uid and gid properties.

-- 
Russ Jones - HP OpenView IT/Operatons support
Raytheon Aircraft Company, Wichita KS
russ_jones@rac.ray.com 316-676-0747

Quae narravi, nullo modo negabo. - Catullus


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

Date: Tue, 08 Aug 2000 17:20:10 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: How to do setuid script on Perl5.6
Message-Id: <3990798A.D24BB6E5@attglobal.net>

Russ Jones wrote:
> 
> Denny Hardian wrote:
> >
> > Hi Perl gurus,
> >   I am trying to make a setuid script on Perl 5.6 however I couldn't do
> > that. Perl doesn't allow me to run setuid. I compiled Perl 5.6 with
> > setuid emulation turned on.
> 

<removed Russ' mindless discussion>

He's right.


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

Date: Tue, 08 Aug 2000 14:05:52 -0400
From: Albert Dewey <timewarp@shentel.net>
Subject: Re: How to open and append to a file
Message-Id: <39904BFF.938F624C@shentel.net>

This is a stripped down version of some code I have used to do precisely
the same thing. I wanted to prepend a file and not append it. This will
do exactly what you want.

## We need to prepend the data file and not append it, hence the two
step process used here

 ## Step 1 - Load the current data file into a variable
 open(FILE,"<../data/inventory.dat") or print "ERROR 404: Cannot open
 ../data/inventory.txt because $!<br>";
 while(<FILE>)
  {
  $OldData .= $_ if $. >= 0
  }
 close (FILE);

 ## Step 2 - Write the data for the item being posted and follow it with
the existing data in the file
 open(POST,">../$Dealer/data/inventory.dat") or print "ERROR 404: Cannot
open ../data/inventory.txt because $!<br>";
 print POST ("$StockNum|$Description|\n");
 print POST ("$OldData");
 close(POST);



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

Date: Tue, 08 Aug 2000 19:36:29 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: How to open and append to a file
Message-Id: <7almy7czpd.fsf@merlin.hyperchip.com>


Albert Dewey <timewarp@shentel.net> writes:

> This is a stripped down version of some code I have used to do precisely
> the same thing. I wanted to prepend a file and not append it. This will
> do exactly what you want.
> 
> ## We need to prepend the data file and not append it, hence the two
> step process used here
> 
>  ## Step 1 - Load the current data file into a variable
>  open(FILE,"<../data/inventory.dat") or print "ERROR 404: Cannot open
> ../data/inventory.txt because $!<br>";
>  while(<FILE>)
>   {
>   $OldData .= $_ if $. >= 0

$. initially has the value 0, and increments with every line added. So,
I don't see a reason why it would be negative. Hence, the if() statement
is unnecessary.

>   }
>  close (FILE);

The following is faster:

	open FILE, "../data/..inventory.dat" or die $!;

	my $OldData;
	{
		local $/;
		$oldData = <FILE>;
	}

But, you should just check the FAQs before whipping up your own
solution (hence saving time and energy).
Checkout perlfaq5:

	How do I change one line in a file/delete a line in a file/
	insert a line in the middle of a file/append to the
	beginning of a file?

--Ala


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

Date: Tue, 08 Aug 2000 13:00:41 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: How to parse an odd file format?
Message-Id: <39904AC9.19099D85@home.com>

Steven Merritt wrote:
> 
> I've got an old logfile that I'm re-writing the interface to. [...]
> The difficulty I'm having is getting the data into a data structure so
> I can manipulate it.
[...]
> At the moment I'm doing something like this(pseudocode)

Unless the problem is with your algorithm, debuggin pseudocode is
pointless. Please post real code, trimmed down as much as possible while
still exhibiting the problem you're having.

Your original description of the file format doesn't seem to match your
later example. E.g, You are assuming that a "Contact" line always
immediately follows a "Who" line, but your sample data has neither.
That's going to throw you out of sync right away.

Here's how I generally parse these sorts of files:

while (<FILE>) {
    if (/a_new_record/) {
        # Do something
    }
    elsif (/some_field/) {
        # Do something
    }
    elsif (/another_field/) {
        # Do something
    }
    elsif (/some_multiline_field/) {
        while (<FILE>) {
            last if /condition_to_break/;
            # Do something
        }
    }
}


That way, if 'some_field' isn't in every record, you can keep moving
ahead, and you'll never process 'some_field' when you should be
processing 'another_field'.

You can also embed backreferences so you don't have to play with
split():

if (/^        Who: (.+)/) {
   $who = $1;
}
elsif (/^        Contact: (.+)/) {
    $contact = $1;
}
etc...

Note the ^ binding... wouldn't want the word 'Contact' inside a
description to cause you to mis-process things.

>    ($junk, $who) = split /Who: /, $_;

If you really don't care about something returned by split(), just
assign it to undef:

(undef, $who) = split(/Who: /, $_);

But as I've said, I prefer using a regex with backreferences.

> There are cases where it aparently gets out of sync even worse and
> gives me nothing but errors on all the splits.  But the input file is
> regular, and I'm not sure what the problem is.

No, and without real code and data, we can't be sure either.
 
> My next step is to try to read in an entire record and then begin
> splitting on newlines, if they contain one of the tags, Who: Status:
> etc, then I know what each line is and how to deal with it, any without
> tags are description by default.

Sounds more like what I suggested. Give it a shot.

-mjc


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

Date: Tue, 08 Aug 2000 13:35:23 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: How to parse an odd file format?
Message-Id: <39906F0B.5CF8407C@ipac.caltech.edu>

Steven Merritt wrote:
> 
> I've got an old logfile that I'm re-writing the interface to.
> Specifically I'm needing to get some more search functionality into it.
> The difficulty I'm having is getting the data into a data structure so
> I can manipulate it.
> 
> The basic layout of the input file is like this
> 
> (space)\n
> +>date timestamp - operator(required)        (optional) status:whatever
>          Who: some guy (optional)
>          Contact: Guy's number(optional)
>          What To: where they want something done(optional)
>          Account: number(optional)
>          blah blah blah whatever was done, sometimes repeating for a lot
>          of lines blah blah blah
> (space)\n

Your examples don't look quite like your definition above, but if I make
them fit your your template, one could do it as I do below my sig. The
code is deliberately under-commented, so you can have the fun of digging
through the perl manuals to figure it out! 

(I defined the record separators exactly as you indicated, a single
space followed by a newline.)

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435

#! /usr/bin/perl -w
use strict;

my @recs;
my ($date,$time,$op,$stat,%fields);

$/ = "\n \n"; # perlvar
while(<DATA>) {
  ($date,$time,$op,$stat) = 
      map { defined $_ ? $_ : "" } # < perlfunc, v perlre and perlop
      /^\+>(\d+)[ \t]+([\d:]+)[ \t]+-(?:[ \t](\w+)(?:[ \t]+(\w+))?)?[
\t]*$/m
      or die "First line doesn't match";
  $_ = $'; # < perlre
  %fields = /^[ \t]*(\S[\S \t]*?)[ \t]*:(?:[ \t]*(\S[\S \t]*?))?[
\t]*$/mg;
  push @recs,[$date,$time,$op,$stat,{%fields},substr($',1)];
}

for (@recs) {
   ($date,$time,$op,$stat) = @$_;
   print "+>$date $time - $op $stat\n";
   while(my ($key,$val)=each %{$_->[4]}) { print "\t$key :
".($val||"")."\n"; }
   print $_->[-1];
}

__DATA__
 
+>20000724 11:06:51 - Geoff
        Application: a4
        Environment: T1
        Referencing Phone: 976-328-7448
        Referencing Party: Duncan McLeod
        Ticket: 2
        Called Duncan. I closed the EER.
 
+>20000724 11:01:59 - nancy
        Application: CI/WW/CX
        Environment: E3
        Referencing Phone:
        Referencing Party: production migration
        Ticket:
        deployed all c0058 and c0193 to production management for header
        ci004991.
        also, deployed cx for fdp01.


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

Date: Tue, 8 Aug 2000 22:38:14 +0200
From: otto.wyss@bluewin.ch (Otto Wyss)
Subject: Howto find module informations in perldoc
Message-Id: <1ef2brw.5zhm5vmx55tsN%otto.wyss@bluewin.ch>

I'd like to know anything about the "Getoptions" in the following script
but I don't know howto use perldoc, i.e.

perldoc Getopt
No documentation found for "Getopt"

---------------------------------------------
#!/usr/bin/perl -w
use strict;
use Getopt::Long;
[...]
Getopt::Long::Configure("bundling");
GetOptions(
 "h+"  => \$help,
 ...¨
);
---------------------------------------------

Also I'd like to understand the statement "Getopt::Long::Conf[..];". How
in perldoc do I find anything about it?

O. Wyss


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

Date: 8 Aug 2000 21:18:14 GMT
From: Erik van Roode <newsposter@cthulhu.demon.nl>
Subject: Re: Howto find module informations in perldoc
Message-Id: <8mptem$i4u$1@internal-news.uu.net>

Otto Wyss <otto.wyss@bluewin.ch> wrote:
> I'd like to know anything about the "Getoptions" in the following script
> but I don't know howto use perldoc, i.e.

> perldoc Getopt
> No documentation found for "Getopt"

Try 'perldoc Getopt::Long'

Erik



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

Date: Tue, 08 Aug 2000 11:21:45 -0700
From: Gorbeast <gorbeast@SPAMSUCKS.subduction.org>
Subject: Re: I need further clarity on rand() etc.
Message-Id: <39904FB9.F4D4A2D9@SPAMSUCKS.subduction.org>

Thank you, I will try this out. 

Walt Mankowski wrote:
> 

> Are you trying to run both of those commands for each line in
> FILE-TO-ACT-ON?  @b = <FH> loads the entire file associated with FH
> and stores it in the array @b.  It leaves FH at the end of the file,
> so if you try to run the command again without either reopening or
> rewinding FH you'll get undef.
> 

Ah.


> Try this instead:
> 
> open (NAMES, $names);
> @names = <NAMES>;
> 
> open (LASTNAMES, $lastnames);
> @lastnames = <LASTNAMES>;
>


maybe you could go into a little more detail here?

As I understand it, we are opening NAMES file, but instead of a file we
associate NAMES with a variable?  What is the significance of that?  The
second line, "@names = <NAMES>" is more familiar to me.  


Thanks for your time!


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

Date: Tue, 08 Aug 2000 18:42:46 GMT
From: Jim Mauldin <mauldin@netstorm.net>
Subject: Re: I need further clarity on rand() etc.
Message-Id: <39905410.10F8F3C3@netstorm.net>

Gorbeast wrote:
> 
> Thank you, I will try this out.
> 
> Walt Mankowski wrote:
> >
> > Try this instead:
> >
> > open (NAMES, $names);
> > @names = <NAMES>;
> >
> > open (LASTNAMES, $lastnames);
> > @lastnames = <LASTNAMES>;
> >
> 
> maybe you could go into a little more detail here?
> 
> As I understand it, we are opening NAMES file, but instead of a file we
> associate NAMES with a variable?  What is the significance of that?  The
> second line, "@names = <NAMES>" is more familiar to me.
> 

It's probably time you did some reading.  It's fun and you'll learn a
lot.  See:

perldoc perlop

and look for I/O Operators and within that, angle brackets, and within
that look for scalar context and list.  See also:

perldoc -f open

-- Jim


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

Date: 08 Aug 2000 17:04:09 -0400
From: Walt Mankowski <waltman@netaxs.com>
Subject: Re: I need further clarity on rand() etc.
Message-Id: <m3ittbsbw6.fsf@netaxs.com>

Gorbeast <gorbeast@SPAMSUCKS.subduction.org> writes:

> Walt Mankowski wrote:
> > Try this instead:
> > 
> > open (NAMES, $names);
> > @names = <NAMES>;
> > 
> > open (LASTNAMES, $lastnames);
> > @lastnames = <LASTNAMES>;
> >
> 
> 
> maybe you could go into a little more detail here?
> 
> As I understand it, we are opening NAMES file, but instead of a file we
> associate NAMES with a variable?  What is the significance of that?  The
> second line, "@names = <NAMES>" is more familiar to me.  

I'm not "associating" anything.  Open is a built-in subroutine that
takes two parameters* -- a file handle and the name of the file.  Your
pseudocode wouldn't have worked as written, so I changed it to have
the filename in a scalar.  Sorry about the confusion.

Walt

* There are also 1- and 3-parameter versions of open.  perldoc -f open
  for more info.



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

Date: Tue, 08 Aug 2000 18:32:15 GMT
From: Ala Qumsieh <aqumsieh@hyperchip.com>
Subject: Re: Interesection and subtraction of data sets.
Message-Id: <7ar97zd2of.fsf@merlin.hyperchip.com>


Brian Lavender <blavender@spk.usace.army.mil> writes:

> I playing around with manipulating sets of data, and I was happy I
> figured out how to find the interection between two sets, and how to
> subtract one set from the other. I looked through the Perl Cookbook, but
> I didn't find anything. Here is what I came up with. Any suggestions?

It is in the Cookbook, as well as the FAQs.
In perlfaq4:

	How do I compute the difference of two arrays?
	How do I compute the intersection of two arrays?

--Ala


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

Date: Tue, 08 Aug 2000 13:26:03 -0800
From: "Jeff Yoak" <jeff@yoak.com>
Subject: Re: Largest files
Message-Id: <8mpjeo04co@news2.newsguy.com>


[posted and mailed]

In article <8mnkbm$usc$1@nnrp1.deja.com>, tosh_v@my-deja.com wrote:

> I have a huge dir structure with .wrp files and I need to get the 10
> biggest or 20 or any number I specify so that i can test my app to see
> ho wit handles the largest files.

I'm sure plenty of people have offered suggestions by now, but I spent a
few minutes trying to do it in a single statement with -e but couldn't
think of a way to trim down the array or take a slice of it in a single
statement.  Maybe someone else did or will.  In the meantime, here is a
solution in case you don't yet have one.

#!/usr/bin/perl
use strict;

my $num = shift or die "Usage: largest <number>\n";
my @files = sort {-s $a <=> -s $b} <*wrp>;
if(scalar @files > $num){
        splice (@files, 0, scalar @files - $num);
}

print "$_\t",-s $_,"\n" foreach @files;




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

Date: 08 Aug 2000 14:22:28 -0500
From: Tony Curtis <tony_curtis32@yahoo.com>
Subject: Re: Largest files
Message-Id: <87ittb36dn.fsf@limey.hpcc.uh.edu>

>> On Tue, 08 Aug 2000 00:30:46 GMT,
>> tosh_v@my-deja.com said:

> Hi, I have a huge dir structure with .wrp files and I
> need to get the 10 biggest or 20 or any number I specify
> so that i can test my app to see ho wit handles the
> largest files.

> Any help on a perl script would be much appreciated.

perldoc File::Find

hth
t
-- 
"With $10,000, we'd be millionaires!"
                                           Homer Simpson


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

Date: Tue, 08 Aug 2000 20:29:50 GMT
From: kaivix@angelfire.com
Subject: Mail::Send Problem!
Message-Id: <25_j5.563$juZ4.9568592@tomcat.sk.sympatico.ca>

How can I place carriage returns in the body of an e-mail message when using 
Mail::Send???

Here is the code I have:

#-------START CODE--------
use Mail::Send;
$msg = new Mail::Send;
$msg->to('user@host');
$msg->subject('Subject');

$fh = $msg->open;

##HERE IS THE PROBLEM:
print $fh qw|
Line1 of e-mail
Line2
Line3
 ...
|;

$fh->close;
#-------END CODE------


What happens with the above code?
The e-mail is successfully sent to the user, BUT look at what it says!:

------------------
Line1Line2Line3
------------------

Why doesn't it show up as:

----------------
Line1
Line2
Line3
----------------

??????!!!

Help me!


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

Date: Tue, 08 Aug 2000 19:27:21 +0100
From: Tim Cockle <T.Cockle@staffs.ac.uk>
Subject: My second forking problem
Message-Id: <39905109.1AFFC5FE@staffs.ac.uk>

Hi, (again),

For those who havn't seen my last message; I am basically writing a
proxy  that sits between the browser and the real-proxy (that
servers my department) parsing HTML.

The code looks  like this:
$server = IO::Socket::INET->new(LocalPort => 3128, Type => SOCK_STREAM,
Reuse => 1, Listen => 10) || die "I can't open a server socket";

$SIG{CHLD} = \&REAPER;
stdout->autoflush(1);

while ($browser = $server->accept()) {
   $proxy = IO::Socket::INET->new("research.soc.staffs.ac.uk:3128") or
die "Could not open socket to reserch proxy\n";
   next if $pid = fork;
   die "fork: $!" unless defined $pid;
   print "child: $pid";
   close($server);

   &DEAL_WITH_CLIENT($browser, $proxy);
   print "child delt with client\n";
   close($browser);
   close($proxy);
   exit;
} continue {
  print "I am a parent: $pid\n";
  close($browser);
  close($proxy);
}

sub REAPER {
 1 until (-1 == waitpid (-1, WNOHANG) );
 $SIG{CHLD} = \&REAPER;
}

The first run seams to work fine. If I then try to download a second
page I get a nasty problem where a child process (i think) crashes out
and I get a system message bassically telling me that a bit of memory
can not be read.

The code works fine if I don't use fork, although I obviusly can't
handle multiple requests. So I think my DEAL_WITH_CLIENT stuff is fine.

Can anyone see a problem with my forking?

Thanks again!

Tim



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

Date: Tue, 08 Aug 2000 21:05:57 +0100
From: Tim Cockle <T.Cockle@staffs.ac.uk>
To: Tim Cockle <T.Cockle@staffs.ac.uk>
Subject: Re: My second forking problem
Message-Id: <39906825.3E937444@staffs.ac.uk>

Hi,

I have narrowed this down to this line:
while ($token = $p->get_tag("a")) {

For this I:
    use HTML::TokeParser;

before this I create the object by:
$p = HTML::TokeParser->new(\*$FILE);

As I said before this works fine with out forking...


Does any one have any general pointers! I am new to both perl and fork so
could do with ANY help that is available!!

Tim




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

Date: Tue, 08 Aug 2000 19:31:41 GMT
From: fathacka@my-deja.com
Subject: Newbie questions: What exactly is $_?
Message-Id: <8mpn6u$d4b$1@nnrp1.deja.com>

I tried searching the documentation on www.perl.com, but nothing seemed
to explicitly state what exactly $_ is.  I also tried searching for it
in the O'Reilly book "Learning Perl", and they use it and state that it
is a "default value", but never explain to full detail what it is.

So I'm posing the question:
What exactly is $_?

I know it is some type of default scalar value.  But how do I know when
I can dump something to it, or extract something from it?  When does it
get used by a subroutine?  When I enter a subroutine, does it have some
default value, like @_?  From what I understand, @_ will be all the
arguments or parameters passed into a subroutine.  Does $_ have this
same type of special assignment, or is it just a default "scratch area"
that is undef until it gets used?

For example:

sub find()
{
   local($text) = @_
   ############
   #LOCATION 1#
   ############
   while (<FILEO>)
   ############
   #LOCATION 2#
   ############
   {
      if (/$text/)
      {
        return 1;
      }
   }
}

At LOCATION 1: what is the value of $_?  Is it undef?
At LOCATION 2: I'm assuming that <FILEO> will dump something into $_

Thanks for any help!


Sent via Deja.com http://www.deja.com/
Before you buy.


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

Date: Tue, 08 Aug 2000 15:45:03 -0400
From: Drew Simonis <care227@attglobal.net>
Subject: Re: Newbie questions: What exactly is $_?
Message-Id: <3990633F.C4920E1B@attglobal.net>

fathacka@my-deja.com wrote:
> 
> I tried searching the documentation on www.perl.com, but nothing seemed
> to explicitly state what exactly $_ is.  I also tried searching for it
> in the O'Reilly book "Learning Perl", and they use it and state that it
> is a "default value", but never explain to full detail what it is.

Did you read perlvar?

http://www.perl.com/pub/doc/manual/html/pod/perlvar.html


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

Date: Tue, 08 Aug 2000 11:09:00 -0700
From: Tim Conrow <tim@ipac.caltech.edu>
Subject: Re: Novice question: How to kill a process
Message-Id: <39904CBC.E5A1AEE0@ipac.caltech.edu>

"Dave @ kexis" wrote:
> 
> Doesn't just using `` execute the command to the shell? But then you might
> as well use sh script for your problem...

Yes, `` invokes a subshell, but some of us prefer to do as much work in
perl as possible. I'd much rather use perl REs, funcs and data
structures than do it in shell. That's why I learned perl in the first
place; 'cause shell programming sucks. The example given is a one liner
in both perl and shell, but if you had to expand it to do more, would
you rather add capability in shell or perl?

--

-- Tim Conrow         tim@ipac.caltech.edu       626-395-8435


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

Date: Tue, 08 Aug 2000 18:15:59 GMT
From: Uri Guttman <uri@sysarch.com>
Subject: Re: OT FS: PerlServices.com Domain Name
Message-Id: <x7hf8v1uw4.fsf@home.sysarch.com>

>>>>> "w" == windywisconsin  <windywisconsin@my-deja.com> writes:

  w> The Domain name 'PerlServices.com' is for sale.  I no longer have the
  w> time to support the site.  The site and scripts also will accompany it
  w> (and the traffic that it draws) if you wish.  If interested, please
  w> make an offer.  Best offer will take it!

  w> Offers can be sent to domain@perlservices.com.

200 quatloos. and that is my final offer!

uri

-- 
Uri Guttman  ---------  uri@sysarch.com  ----------  http://www.sysarch.com
SYStems ARCHitecture, Software Engineering, Perl, Internet, UNIX Consulting
The Perl Books Page  -----------  http://www.sysarch.com/cgi-bin/perl_books
The Best Search Engine on the Net  ----------  http://www.northernlight.com


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

Date: Tue, 8 Aug 2000 14:47:42 -0700
From: "Jürgen Exner" <juex@deja.com>
Subject: OT: Re: Converting from US dates/numbers to European dates/numbers
Message-Id: <39907ffe$1@news.microsoft.com>

"Godzilla!" <godzilla@stomp.stomp.tokyo> wrote in message
news:39907571.84C66663@stomp.stomp.tokyo...
> Logan Shaw wrote:
[..]
> You boys will be exceptionally challenged to substantiate
> your claims decimal points are not needed in mathematics.

Ad 1: Would you mind citing any such claim?
Ad 2: Aren't you confusing the implementation (in firmware or hardware) of
mathematical operations in a CPU or math CoPro, the representation of
numbers in programming languages, and mathematics? After all your example
"2.2" would be e.g. "0032 002C 0032"(HEX) in Unicode. Where do you see (or
where does a CPU see) a decimal separator?
Ad 3: If you really want to you could do without a decimal separator:

2,2 + 2,2 (in European notation) is exactly the same as 22*10^-1 + 22*10^-1,
which doesn't contain a single decimal separator.

But what would be the point?

jue




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

Date: Tue, 8 Aug 2000 20:01:50 +0100
From: "Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk>
Subject: Parse::RecDescent: @item woes
Message-Id: <965761437.27807.0.nnrp-12.9e98901a@news.demon.co.uk>

I'm having trouble seeing how to use the @item
array elements generated in a Parse::RecDescent
grammar. Consider the following simple grammar
that parses expressions like "((6));" or
"(((5)));" i.e. a number stuck in the middle of
a balanced set of ().

-----------------------------------------------
DoNest: Nest ';' { print "It's a nest\n"; }

Nest: Number          |
      '(' SubNest ')'

SubNest: Nest

Number: /\d+/
-----------------------------------------------

I've been trying to solve the apparently simple
task of printing out the Nest recognized by
the DoNest rule. I tried changing the DoNest
action to:

{ print "It's a nest: $item[1]\n"; }

but as it stands, this prints out ")" for any
valid input containing a () pair. OK, so I reason
that this is because the Nest rule is returning the
last element of @item - the docs seem to say that is
the default.  So, I add an action for the second
alternative of the Nest rule, like this:

{ $return = [ @item[1..$#item] ]; }

and change the DoNest action to match:

{ print "It's a nest: @{$item[1]}\n"; }

Great, now, if I parse data like "(6);", it
correctly prints "It's a nest: ( 6 )".
But, if I enter another legal Nest, like "((6));"
or "6;", I get "It's a nest: ( ARRAY(0x8313448) )"
and an error telling me that I can't use 6 as
an ARRAY ref etc, respectively.

Okay, so I can change the Nest action to test
$item[1] for refness, and write code to deref
an arbitrarily deep stack of array refs, but I
think I'm missing the point - presumably, there's
an easier way to do it than this.

Part of my problem seems to be that my Nest rule can
return either a ref, or a number, and the Nest/SubNest
recursion can make the refs go arbitrarily deep.

I have in fact found a solution: I make both alternatives
in Nest return refs by changing the Nest rule to be:

    Nest:   Number
              { [ $item[1] ]; }
          |
            '(' SubNest ')'
              { [ @item[1..$#item] ]; }

and calling a function that handles the nested refs
recursively in the DoNest action:

DoNest: Nest ';' { print "It's a nest: "; ::PrintNest($item[1]); }

However, this seems like a heck of a lot of work
for a trivial problem.

Is this an issue that everyone runs into ? Am I
expecting things to be unreasonably simple ? This
solution (and all the others I could think of) seem
that I have to pay very careful attention to what
I return in all the rules - maybe that's just the
way it is, but I'd like to know if there's an easier
way if possible.

Steve Collyer.









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

Date: 8 Aug 2000 22:02:39 GMT
From: damian@cs.monash.edu.au (Damian Conway)
Subject: Re: Parse::RecDescent: @item woes
Message-Id: <8mq01v$pt1$1@towncrier.cc.monash.edu.au>

"Stephen Collyer" <stephen@twocats.dont-spam.demon.co.uk> writes:

>I'm having trouble seeing how to use the @item
>array elements generated in a Parse::RecDescent
>grammar. Consider the following simple grammar
>that parses expressions like "((6));" or
>"(((5)));" i.e. a number stuck in the middle of
>a balanced set of ().

>-----------------------------------------------
>DoNest: Nest ';' { print "It's a nest\n"; }

>Nest: Number          |
>      '(' SubNest ')'

>SubNest: Nest

>Number: /\d+/
>-----------------------------------------------

If you just want the original string that matched the entire
nest do this:

	DoNest: Nest ';' { print "It's a nest: $item[1]\n"; }

	Nest: Number
	    | '(' Nest ')' { $return = "($item[2])" }

Damian


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

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


Administrivia:

The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc.  For subscription or unsubscription requests, send
the single line:

	subscribe perl-users
or:
	unsubscribe perl-users

to almanac@ruby.oce.orst.edu.  

| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.

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 V9 Issue 3953
**************************************


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