[18601] in Perl-Users-Digest
Perl-Users Digest, Issue: 769 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Apr 25 21:10:27 2001
Date: Wed, 25 Apr 2001 18:10:12 -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: <988247412-v10-i769@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 25 Apr 2001 Volume: 10 Number: 769
Today's topics:
Re: perl variables problem (Anno Siegel)
Re: Please help <wyzelli@yahoo.com>
Re: Read text files of different format <mischief@velma.motion.net>
Re: Running Command Line Commands <miltonroad@btinternet.com>
Re: SGI IRIX fork() syscall: child process doesn't term (Walter Roberson)
Re: SGI IRIX fork() syscall: child process doesn't term <mjo@dojo.mi.org>
Re: SGI IRIX fork() syscall: child process doesn't term <scotth@sgi.com>
Re: SGI IRIX fork() syscall: child process doesn't term <bcasavan@sgi.com>
Re: Tcl is faster then perl. <bart.lateur@skynet.be>
Re: Tcl is faster then perl. (Steve)
Re: Tcl is faster then perl. <bart.lateur@skynet.be>
Re: Tcl is faster then perl. (Chris Fedde)
Re: total newbie (Greg Bacon)
Re: Want to use undef in dbmopen (Anno Siegel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: 25 Apr 2001 22:19:46 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: perl variables problem
Message-Id: <9c7ii2$lfm$1@mamenchi.zrz.TU-Berlin.DE>
According to Chris Stith <mischief@velma.motion.net>:
> Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> wrote:
> > According to Sylvain Thevoz <sylvain.thevoz@mcnet.ch>:
> >> I have a file which contents:
> >> $a Mr. Smith, how do you do?
>
> > Avoid the use of variables $a and $b. See perldoc -f sort for why.
>
> >> I have a perl file which contents:
> >> $a = "good morning";
> >> open(FILE, "file.lst");
> >> while (<FILE>)
> >> {
> >> $out .= $_;
> >> }
> >> print $out;
> >>
> >> My problem:
> >> when I execute the perl file, it prints "$a Mr. Smith, how do you do?"
> >>
> >> But I want to print "good morning Mr. Smith, how do you do?"
>
> > Didn't we have this exact question last week?
>
> > Here is one way to do what you want:
>
> > my $line = '$x Mr. Smith, how do you do?';
> > my $x = 'Good morning';
> > print $line, ' -> ', eval "qq/$line/", "\n";
> > Prints:
> > $x Mr. Smith, how do you do? -> Good morning Mr. Smith, how do you do?
>
> > While this is probably more or less what you had in mind with your
> > code, it is insecure, as always when you use string eval with data
> > that come from outside your program. If someone changed your file
> > to read "$x Mr./Ms. Smith, how do you do?" your program will crash,
> > and there are worse things that could happen.
>
> > A safer way to accomplish the same thing is to use a substitution
> > operator: "$line =~ s/\$x/$x/g". Of course, now there is no need
> > to name the bit that has to be substituted like the Perl variable
> > that contains the substitution, any unique string would do. This
> > further decouples the program from the data, which is a good thing.
>
> ...but you don't have to eval the whole thing. You don't really even
> have to eval anything from the file.
>
> s/\$a/$a/;
Why, yes. That's what I suggest im my last paragraph above.
I only brought up the eval thing to show the OP how to make
happen what he (I guessed) expected to happen all by itself.
Anno
------------------------------
Date: Thu, 26 Apr 2001 09:19:18 +0930
From: "Wyzelli" <wyzelli@yahoo.com>
Subject: Re: Please help
Message-Id: <59JF6.5$845.2032@vic.nntp.telstra.net>
"John W. Krahn" <krahnj@acm.org> wrote in message
news:3AE68065.EA1EF698@acm.org...
>
> $ perl -e 'print map { $_ % 10 ? "$_, " : "tenth\n" } ( 101 .. 150 )'
> 101, 102, 103, 104, 105, 106, 107, 108, 109, tenth
> 111, 112, 113, 114, 115, 116, 117, 118, 119, tenth
> 121, 122, 123, 124, 125, 126, 127, 128, 129, tenth
> 131, 132, 133, 134, 135, 136, 137, 138, 139, tenth
> 141, 142, 143, 144, 145, 146, 147, 148, 149, tenth
According to the specs::
Create another Perl file named a1-q3.pl that contains: (6 marks)
a numerical array containing the numbers from 101 to 150
create and execute a function (or "subroutine") which will replace every
tenth item in the array with the word "tenth"
print the entire array on screen with 10 items printed per line and each
item separated with a comma and a space (", ")
No file created -1 mark of 1
No Numerical Array -1 mark of 1
No function (or "subroutine") created -2 marks of 2
Prints screen properly, but is not printing an array (as it does not
exist) -1 of 2
Scores 1/6 :(
Geez I'm a hard task master... LOL <grin>
Wyzelli
--
($a,$b,$w,$t)=(' bottle',' of beer',' on the wall','Take one down, pass it
around');
for(reverse(1..100)){$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n$_$a$s$b\n$t\n";
$_--;$s=($_!=1)?'s':'';$c.="$_$a$s$b$w\n\n";}print"$c*hic*";
------------------------------
Date: Wed, 25 Apr 2001 22:11:32 -0000
From: Chris Stith <mischief@velma.motion.net>
Subject: Re: Read text files of different format
Message-Id: <teeisk3mgvbbf1@corp.supernews.com>
Samuel Thomas <sthomas@ws5120.nc.fnc.fujitsu.com> wrote:
> I was under the impression that perl handled the os specific detials
> for you and you could just look for "\n". (This was after reading a
> similar question in the Perl Cookbook)
It handles going from "\n" to the native line ending and back
just fine. It's when you have files that are not native to
your platform and which follow a different line ending scheme
that it's an issue.
DOS/Win uses : \012\015
Mac uses : \015
Unixy things use: \012
All of these use "\n" from within C and Perl to mean newline.
Chris
--
Disclaimer: Actual product may not resemble picture in ad in any way.
------------------------------
Date: Thu, 26 Apr 2001 00:46:17 +0100
From: Milton Road <miltonroad@btinternet.com>
Subject: Re: Running Command Line Commands
Message-Id: <QsIF6.130978$g63.15049620@nnrp3.clara.net>
Wooah!
I think you've got the wrong idea here buddy.
Apache isn't a "Linux command". It's a webserver which runs on a lot of
different platforms. It is particularly prolific on Linux set-ups, but
that doesn't mean it /is/ Linux.
It's a bit like saying IE is a "Windows command". Sure, IE is prolific on
Windows but there is a Mac port too.
If you're running on Windows you need to run Windows system commands,
namely rename ( or move ) and del. The system command won't find mv or rm
on your box because they're not there.
You may also need to change your path delimiter from / to \. You'll need
to escape the backslash to give it its literal meaning if you're placing
your paths within double quotes ( which you are, because you're
interpolating variables ).
I think that should sort you out, although I will leave you with a gentle
piece of advice: this probably isn't the group to ask about changing file
permissions, Windows or otherwise.
Good luck,
Milton
Sh0t2Bts wrote:
> Hi All,
>
> I am a Intranet Developer "Just Starting" I use two Linux RH6.0 machines
> at work, which host the Company Intranet
>
> The problem I have is that at home I only have 1 PC, Win 98 SE, with
> apache installed,
> The apache server workes fine
> When it comes to running cgi scripts again all works fine until I try to
> use command line commands
> The the scripts works but it does not exeute the command line commands. I
> use the following two:-
>
> system("mv $dirname/$line
> ../testfiles/finished/@dirmeanings[$b]_20010425.html");
> system("rm $dirname/$line -f");
>
> I know that MV & RM are both Linux commands but as so is apache I though
> that this would work...
>
> I few things that I though it could be was the rights on the files I am
> trying to move ar set to Read and Execute only!
> The dircectory I am trying to write to again is only Read only.
>
> If this is true how do I change the rights in Windows??
>
> If this is not the case could someone please advise another way round
> this???
>
> Thanks in Advance
>
>
> Mark
>
>
>
------------------------------
Date: 25 Apr 2001 22:35:21 GMT
From: roberson@ibd.nrc.ca (Walter Roberson)
Subject: Re: SGI IRIX fork() syscall: child process doesn't terminate after exit
Message-Id: <9c7jf9$ncu$1@canopus.cc.umanitoba.ca>
In article <9c7guh$f2q$1@hatathli.csulb.edu>,
Matthew Black <black@csulb.edu> wrote:
:PROBLEM:
:We are having trouble with the fork() system call in Perl. When a
:child process exits, the process lingers as <defunct> rather than
:disappearing. These lingering <defunct> processes disappear only after
:the parent process gets terminated.
That is what *should* happen until you wait() or waitpid()
See even the perlfunc man page:
fork Does a fork(2) system call. Returns the child pid to the parent
process and 0 to the child process, or undef if the fork is
unsuccessful. Note: unflushed buffers remain unflushed in both
processes, which means you may need to set $| ($AUTOFLUSH in
English) or call the autoflush() method of IO::Handle to avoid
duplicate output.
If you fork() without ever waiting on your children, you will
accumulate zombies:
------------------------------
Date: Wed, 25 Apr 2001 22:28:18 GMT
From: Mike O'Connor <mjo@dojo.mi.org>
Subject: Re: SGI IRIX fork() syscall: child process doesn't terminate after exit
Message-Id: <010425222818.AA25439@dojo.mi.org>
I can't duplicate this, running as root or a normal user. My setup:
% hinv |grep IP
16 300 MHZ IP27 Processors
CPU: MIPS R12000 Processor Chip Revision: 2.3
FPU: MIPS R12010 Floating Point Chip Revision: 2.3
% uname -R
6.5 6.5.12f
% perl -v
This is perl, version 5.004_04 built for irix-n32
Is this supposed to happen all the time? Do you possibly have any
interesting shell limits, systune-ables, or the like? Do you have
2+ 6.5 IRIX systems where you can test this on?
In article <9c7guh$f2q$1@hatathli.csulb.edu>,
Matthew Black <black@csulb.edu> wrote:
:PROBLEM:
:We are having trouble with the fork() system call in Perl. When a
:child process exits, the process lingers as <defunct> rather than
:disappearing. These lingering <defunct> processes disappear only after
:the parent process gets terminated.
:
:This problem was observed on our
:Origin 200 systems running IRIX 6.5.x (6.5.10m and 6.5.6m).
:It did NOT occur with a Challenge S running IRIX 6.2.
:
:
:I've attached the relevant code from a file named fork-test.pl.
:It can be run from the shell by simply typing "./fork-test.pl".
:I ran this program on my X-terminal to monitor the output in one
:window and the process status in a second.
:
:
:Is fork() broken under IRIX 6.5?
:
:
:# perl -v
:This is perl, v5.6.1 built for IP27-irix
:
:> perl -v
:This is perl, version 5.004_04 built for irix-n32
:
:
:matthew black
:network services
:california state university, long beach
:
:
:--- SCREEN 1: RUNNING THE PROGRAM ------------------------------------------
:
:postman 6# ./fork-test.pl
:Parent process 5918279 here to test perl fork() function.
:
:
:[PARENT] About to fork()...
:[CHILD] here with PID 6120522
:[CHILD] sleeping 10 seconds...
:[PARENT] Child process is 6120522
:[PARENT] returning
:[CHILD] exiting...
:
:[PARENT] About to fork()...
:[CHILD] here with PID 6129264
:[CHILD] sleeping 10 seconds...
:[PARENT] Child process is 6129264
:[PARENT] returning
:[CHILD] exiting...
:
:[PARENT] About to fork()... (typed ^C here to abort)
:
:
:--- SCREEN 2: PROCESS LISTING ----------------------------------------------
:NOTE: 5918279 is the master PID from screen 1.
:
:postman 37# ps -aef | grep 5918279
: root 5918279 5943761 0 09:24:58 pts/2 0:00 /usr/sbin/perl
:./fork-test.pl
: root 6120522 5918279 0 - - 0:00 <defunct>
: root 6128101 5973232 0 09:25:23 pts/1 0:00 grep 5918279
: root 6129264 5918279 0 09:25:17 pts/2 0:00 /usr/sbin/perl
:./fork-test.pl
:
:
:--- SOURCE CODE ------------------------------------------------------------
:
:#!/usr/local/bin/perl
:#
:# FORK-TEST.PL
:# Runs endlessly...terminate with CONTROL-C.
:# Make sure your shell supports that: stty -intr ^C
:
: print "Parent process $$ here to test perl fork() function.\n";
: print "\n";
:
: while (-1) {
: print "\n[PARENT] About to fork()...\n";
: sleep 3;
: forktest();
: sleep 12;
: }
: exit;
:
:sub forktest {
:
:FORK: {
: if ($pid = fork) {
: # parent here
: # child process pid is $pid
: print "[PARENT] Child process is $pid\n";
: print "[PARENT] returning\n";
: }
: elsif (defined $pid) { # $pid is zero here if defined
: # child here
: # parent process pid available with getppid
: print "[CHILD] here with PID $$\n";
: print "[CHILD] sleeping 10 seconds...\n";
: sleep 10;
: print "[CHILD] exiting...\n";
: exit;
: }
: elsif ($! =~ /No more processes/) {
: # EAGAIN, supossedly recoverable fork error
: print "EAGAIN error\n" if $opt_d;
: sleep 5;
: redo FORK;
: }
: else {
: # other fork error
: print "FORK ERROR!\n" if $opt_d;
: }
: }
: return;
:}
:
:--- END OF NH-010425-01 ----------------------------------------------------
:
--
Michael J. O'Connor | WWW: http://dojo.mi.org/~mjo/ | Email: mjo@dojo.mi.org
Royal Oak, Michigan | (has my PGP & Geek Code info) | Phone: +1 248-427-4481
------------------------------
Date: 25 Apr 2001 15:45:52 -0700
From: Scott Henry <scotth@sgi.com>
Subject: Re: SGI IRIX fork() syscall: child process doesn't terminate after exit
Message-Id: <yd8g0ewlhsv.fsf@hoshi.engr.sgi.com>
>>>>> "M" == Matthew Black <black@csulb.edu> writes:
M> PROBLEM:
M> We are having trouble with the fork() system call in Perl. When a
M> child process exits, the process lingers as <defunct> rather than
M> disappearing. These lingering <defunct> processes disappear only after
M> the parent process gets terminated.
Before even looking at the code, I would have guessed that you
weren't wait()ing on the children. This is standard Unix behavior.
--
Scott Henry <scotth@sgi.com> / Help! My disclaimer is missing!
IRIX/Linux MTS, / http://reality.sgi.com/scotth/
Silicon Graphics, Inc / SGI-One step ahead
------------------------------
Date: Wed, 25 Apr 2001 17:51:13 -0500
From: Brent Casavant <bcasavan@sgi.com>
To: Matthew Black <black@csulb.edu>
Subject: Re: SGI IRIX fork() syscall: child process doesn't terminate after exit
Message-Id: <Pine.SGI.4.21.0104251740010.38971-100000@kzerza.americas.sgi.com>
[posted and replied]
On 25 Apr 2001, Matthew Black wrote:
> PROBLEM:
> We are having trouble with the fork() system call in Perl. When a
> child process exits, the process lingers as <defunct> rather than
> disappearing. These lingering <defunct> processes disappear only after
> the parent process gets terminated.
Well, I'll admit to not being a Perl guru, but I'm pretty sure I know
what the problem is.
The parent process needs to catch the SIGCHLD signal, then perform
a "wait()" system call to read the child's exit status. This is
necessary because the kernel cannot free up the child's state
(including the exit status) until somebody reads that exit status.
You are observing child processes stuck in the "zombie" (not quite
dead, not quite alve) state.
The reason they go away when the parent exits is that the children
are inheirited by the init process (pid 1), which always catches
SIGCHLD and performs a wait(), causing the zombies to die for good.
> This problem was observed on our
> Origin 200 systems running IRIX 6.5.x (6.5.10m and 6.5.6m).
> It did NOT occur with a Challenge S running IRIX 6.2.
I cannot explain this, other than a possible difference in the Perl
binaries. One of them may have "silently" done a signal()/wait()
without needing user intervention.
You need to do something like this in your Perl program:
=====
sub chldhandler {
my ($childpid);
$childpid = wait();
$SIG{'CHLD'} = \&chldhandler; # Reestablish signal handler
if ($childpid != -1)
{
print "Child process $childpid exited with status $?\n";
}
}
$SIG{'CHLD'} = \&chldhandler; # Establish signal handler
=====
Hope that helps,
Brent Casavant
--
Brent Casavant bcasavan@sgi.com
Kernel Engineer http://reality.sgi.com/bcasavan
Silicon Graphics, Inc.
------------------------------
Date: Wed, 25 Apr 2001 20:44:02 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Tcl is faster then perl.
Message-Id: <tndeetkb0cpnt00jjpmp80uumh1l4r9134@4ax.com>
Wenzel, Joel [CAR:VS11:EXCH] wrote:
>Perl is in fact faster then Tcl according to
>several benchmark tests I'v found but I don't have a clue why since the
>newer versions of Tcl have been improved.
Because the newest TCL is now properly compiled, just like Perl? It's
still bytecode... but originally, TCL was run as text, with
interpretation of the source on the fly. Run some piece of code 10 times
in a loop, and it will be parsed 10 times. But not any more.
--
Bart.
------------------------------
Date: 25 Apr 2001 22:56:57 GMT
From: steve@zeropps.uklinux.net (Steve)
Subject: Re: Tcl is faster then perl.
Message-Id: <slrn9eek8s.hib.steve@zero-pps.localdomain>
On Wed, 25 Apr 2001 16:50:55 -0400, Wenzel, Joel [CAR:VS11:EXCH] wrote:
>Tcl today is slower then perl. A few years ago, Tcl was not compilied and
>it did not
>have binary support. Perl had both. Today, however, Tcl has these features
>and is
>still much slower then perl in many areas. I need to know why Tcl is slower
I think you've probably answered your own question here, the
perl people have been doing it for longer, and so know how far
various aspects can be pushed. A bit liek two companies both
making TV sets, company OneA have been making the sets for 30
years, and company TwoB have been making sets for 10 years, how
come company OneA's sets are better than company TwoB's?
--
Cheers
Steve email mailto:steve@zeropps.uklinux.net
%HAV-A-NICEDAY Error not enough coffee 0 pps.
web http://www.zeropps.uklinux.net/
or http://start.at/zero-pps
11:25pm up 83 days, 11 min, 2 users, load average: 2.00, 2.00, 2.00
------------------------------
Date: Wed, 25 Apr 2001 23:25:41 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Tcl is faster then perl.
Message-Id: <0aneetkf3rl1haad489qk90usnj0o73h7r@4ax.com>
Steve wrote:
>A bit liek two companies both
>making TV sets, company OneA have been making the sets for 30
>years, and company TwoB have been making sets for 10 years, how
>come company OneA's sets are better than company TwoB's?
Better dog food?
--
Bart.
------------------------------
Date: Thu, 26 Apr 2001 00:12:14 GMT
From: cfedde@fedde.littleton.co.us (Chris Fedde)
Subject: Re: Tcl is faster then perl.
Message-Id: <yJJF6.12$T3.170609152@news.frii.net>
In article <3AE7492D.3D7DEC91@americasm01.nt.com>,
Wenzel, Joel [CAR:VS11:EXCH] <coopvs14@americasm01.nt.com> wrote:
>Gwyn Judd wrote:
>
>> I'm not sure what you are trying to do here. This group is actually
>> concerned with Perl, not Tcl. If you have a Perl question then ask that.
>> If you have a question about why Tcl is slow, ask it in a group about
>> Tcl. If you are just trolling (as seems to be the case) then you should
>> really be crossposting this to comp.lang.tcl and
>> alt.binaries.multimedia.aviation as well for maximum effect.
>>
>I meant to ask why perl is fast...not why Tcl is slow. Sorry for the
>misconception
>
Perl is fast because a lot of talented people worked very hard over
a lot of years to make it so.
For a given task perl is faster or slower than for instance tcl
because the person writing the program knew more or less about one
or the other programming languages and chose some sub-optomal or
super-optomal way of implementing the task.
All that asside though the true economy is in the time that it
takes you to solve the problem you are working on. Perl is the
right language for the problem you are working on IFF you can solve
the problem "better" with it than with some other language.
chris
--
This space intentionally left blank
------------------------------
Date: Wed, 25 Apr 2001 22:51:18 -0000
From: gbacon@HiWAAY.net (Greg Bacon)
Subject: Re: total newbie
Message-Id: <teel765v1tds8b@corp.supernews.com>
In article <3ae6feee.837196@news-server>,
Gil G. <gil@nospam-keskydee.com> wrote:
: >Gee, then what's that perly.y business in the perl source?
:
: Hum... If you mean that an interpreter compiles on the fly, sure...
: As to perly.y, enlight me please..
No, I don't mean that an interpreter compiles on the fly. Your perl
binary contains at least two compilers: a Perl compiler (that uses a
parser generated from perly.y) and a Perl regular expression compiler.
Your perl binary also contains an interpreter, but it's a PP code
interpreter, not a Perl interpreter.
Greg
--
To be pedantic,
the word 'haiku' has three
not two syllables
-- Neko
------------------------------
Date: 25 Apr 2001 23:23:17 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Want to use undef in dbmopen
Message-Id: <9c7m95$o9c$1@mamenchi.zrz.TU-Berlin.DE>
According to Yash Sathaye <ysathaye@vignette.com>:
> Hi:
>
> I am using dbmopen and since I want to PERL to just access a database and
> not create it, if it does not exist, I am using undef. It looks some thing
> like:
>
> dbmopen( %OPTS, 'Options', undef) || die "Can not open Options :$!";
> I am also using strict module. The only problem is that when I run the
> script I get the following warnings:
>
> Use of uninitialized value at script.pl line 100.
Wow. Yes dbmopen() doesn't seem to work as advertised. I guess
that's technically a bug (in 6.0), but dbmopen() is deprecated.
You should use tie instead, which doesn't have this problem.
To circumvent it, you could locally switch off warnings:
"{ no warnings; dbmopen( ...); }".
Anno
------------------------------
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 769
**************************************