[11802] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5402 Volume: 8

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Apr 16 18:07:26 1999

Date: Fri, 16 Apr 99 15:00:19 -0700
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Fri, 16 Apr 1999     Volume: 8 Number: 5402

Today's topics:
        "Dynamic Download" application with Perl5 <sspringett@cwe2.com>
    Re: copyto URL (Abigail)
        DateCalc not working properly <tedder@pacifier.com>
        Dynaloader problem after Perl upgrade eugene@vertical.net
    Re: fork processes in batches <tchrist@mox.perl.com>
    Re: How to open file across network <cassell@mail.cor.epa.gov>
    Re: like print <<...; load a variable? (Tad McClellan)
    Re: like print <<...; load a variable? <cassell@mail.cor.epa.gov>
    Re: Need info on Perl vs. VB for manager persuasion (Tad McClellan)
    Re: Need info on Perl vs. VB for manager persuasion <stevenjm@olywa.net>
        Need password HELP!! <starwolf@rahul.net>
    Re: New FAQ: How can I read in an entire file all at on <uri@home.sysarch.com>
    Re: New FAQ: How can I read in an entire file all at on <tchrist@mox.perl.com>
    Re: Open an THML file but don't display it (Tad McClellan)
        Perl Power Tools status update <tchrist@mox.perl.com>
        Sorting question <paul@breslaw.demon.co.uk>
    Re: Sorting question (Larry Rosler)
        which way is better to reap child processes? <tbc@col.hp.com>
    Re: why won't this statement work @array=<*.*> (Tad McClellan)
    Re: Would anyone care to teach me perl? (Daniel Beckham)
    Re: zipped perlman <lanny.gilbert@bellsouth.net>
    Re: { } question/problem (David Walford)
        Special: Digest Administrivia (Last modified: 12 Dec 98 (Perl-Users-Digest Admin)

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

Date: Fri, 16 Apr 1999 20:53:45 GMT
From: "Steve Springett" <sspringett@cwe2.com>
Subject: "Dynamic Download" application with Perl5
Message-Id: <trNR2.2697$RD5.154861682@dca1-nnrp1.news.digex.net>

I have an existing Perl application which accesses a SQL database.  I'm
currently using Win32:ODBC for this task and it seems to work fine.  I have
a field in our SQL database which is rather large.  It's configured as a
BLOB.

There are several different rows in the database which are constantly
changing and each row has a different value of this BLOB field.

What I would like to happen is to have the option for the end user to
download (as a file) the contents of the BLOB.  The data in this field is
all text based and is generally about 50-80K in size.

I would like to stay away from creating a temporary text file for the
download.  What I would like is to have the perl application essentually
'stream' the download to the user in the form of a file.

Does any of this sound realistic and if so, I can I go about accomplishing
this?

Thanks

Steve Springett




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

Date: 16 Apr 1999 20:22:55 GMT
From: abigail@fnx.com (Abigail)
Subject: Re: copyto URL
Message-Id: <7f866v$99r$1@client2.news.psi.net>

Phillip Grobler (info@grobler.co.za) wrote on MMLIV September MCMXCIII in
<URL:news:37176540.88D27949@grobler.co.za>:
$$ How can one copy a file to a url or from a url from a perl script


That depends on the scheme of the URL. For http URLs, one would use
PUT and GET repectively. But it'll be different for say, an NFS url.



Abigail
-- 
sub _'_{$_'_=~s/$a/$_/}map{$$_=$Z++}Y,a..z,A..X;*{($_::_=sprintf+q=%X==>"$A$Y".
"$b$r$T$u")=~s~0~O~g;map+_::_,U=>T=>L=>$Z;$_::_}=*_;sub _{print+/.*::(.*)/s}
*_'_=*{chr($b*$e)};*__=*{chr(1<<$e)};
_::_(r(e(k(c(a(H(__(l(r(e(P(__(r(e(h(t(o(n(a(__(t(us(J())))))))))))))))))))))))


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

Date: 16 Apr 1999 14:46:10 PST
From: Ted Timmons <tedder@pacifier.com>
Subject: DateCalc not working properly
Message-Id: <3717afa2.0@news.pacifier.com>

I've been using DateCalc for over a year now for various admin tasks, such
as automatic reminders when our users passwords are about to expire - so
they don't bug us after they expire :^)

But now I've got it installed on a Caldera 1.3 box - that's a Linux
flavor. First, it didn't install to a path in the @INC - it installed to
/usr/lib/perl5/site-perl/Date/Calc.pm instead of
/usr/lib/perl5/site_perl/5.005/i586-linux/Date/Calc.pm. So I put a symlink
in the latter location for it. Now the "use" line works, and all the
functions that I call work, but dates_difference doesn't! Why?!

FWIW, "make test" was successful when I ran it.

Undefined subroutine &Date::DateCalc::dates_difference called at
 ./check_expire.pl line 94.    

Again, thanks for your help.


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

Date: Fri, 16 Apr 1999 20:34:08 GMT
From: eugene@vertical.net
Subject: Dynaloader problem after Perl upgrade
Message-Id: <7f86rv$gcj$1@nnrp1.dejanews.com>



We upgraded Perl and something broke: all the scripts that use modules
that rely on Dynaloader.pm are now failing like this:


Can't load '/usr/local/lib/perl5/site_perl/sun4-solaris/auto/DBI/DBI.so'
for module DBI: ld.so.1: /bin/perl: fatal: relocation error: symbol not
found: dirty: referenced in
/usr/local/lib/perl5/site_perl/sun4-solaris/auto/DBI/DBI.so at
/usr/local/lib/perl5/5.00503/sun4-solaris/DynaLoader.pm line 169.

All the referenced files exist.


I've run out of ideas here.


Eugene

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


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

Date: 16 Apr 1999 14:01:21 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: fork processes in batches
Message-Id: <37179711@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, lr@hpl.hp.com (Larry Rosler) writes:
:> Here's a trivial little version I whipped up in about ten minutes.
:> 	    print "Child $child exited " . ($? << 8) . "\n" if $?;
:  	    print "Child $child exited " . ($? >> 8) . "\n" if $?;

Right.  That's what you get for 10 minutes of work. :-)

--tom
-- 
"I've decided I don't want to be a manager.  Every time you try to be responsive to your employees, they 
say you're being reactive and not proactive.  And when you try to be proactive, they accuse you 
of being capricious and arbitrary.  So I don't wanna be a manager...  " --Larry Wall


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

Date: Fri, 16 Apr 1999 13:58:13 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: How to open file across network
Message-Id: <3717A465.9FBA47BA@mail.cor.epa.gov>

qinqiang sun wrote:
> 
> Hi, everyone,
> 
> I tried to open file on another machine by specifying the driver map
> letter and failed. Could you please help me on this? Thank you.
> 
> I also failed to open MS access database on another machine even though
> local database has no problem.
> 
> Please give me some clues.

We would be happy to, but you have given us no information.
I deduce from your words that you are on an NT network, but that 
doesn't guarantee that all your machines are NT.

What version of Perl?
What code works, and what code fails?  What error messages did you get?
Are you trying to make a connection using HTTP?  Sockets?  What?
Do you have permissions for all of these files?  Does your program?

Help us out a little.

David
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Fri, 16 Apr 1999 15:09:39 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: like print <<...; load a variable?
Message-Id: <jt18f7.aoa.ln@magna.metronet.com>

Leo Schalkwyk (schalkwy@minnie.RZ-Berlin.MPG.DE) wrote:
: I'm sure I'm not the only one who had totally missed the existence
: of  single-quotish here-documents in the docs. Is it a recent
: feature or  have I been asleep for ages? 


   And I didn't even mention the backticked here-doc...

print <<`ENDLS`;
ls -l
ENDLS


   I think you have been asleep  :-)


: Discussion of here documents in the man pages seems to be a bit thin
: (unless I missed most of it) perhaps because of the assumption that
: people know all about them because of shell traditions.  


   Probably.

   They seem adequately covered in perldata.pod.

   What is missing there?


: For example
: it might be logical to mention them in  the section of perlop on
: quote and quote-like operators?  


   I agree.


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 16 Apr 1999 14:16:12 -0700
From: David Cassell <cassell@mail.cor.epa.gov>
Subject: Re: like print <<...; load a variable?
Message-Id: <3717A89C.7472B9BB@mail.cor.epa.gov>

Tad McClellan wrote:
> 
> Leo Schalkwyk (schalkwy@minnie.RZ-Berlin.MPG.DE) wrote:
> : I'm sure I'm not the only one who had totally missed the existence
> : of  single-quotish here-documents in the docs. Is it a recent
> : feature or  have I been asleep for ages?
> 
>  [my trim]
>    I think you have been asleep  :-)

But to be fair to Leo, one's prior exposure to here-docs may have a
lot to do with how long it is before you find them.  It did for me.
My non-shell-programming background led me to think in other directions.
Somehow I even missed them the first time I read through the documents.
It wasn't until I saw someone use a here-doc in an example in this ng
(some time ago) that I realized they were there.. or that they were
there in shell programming too.
 
> : Discussion of here documents in the man pages seems to be a bit thin
> : (unless I missed most of it) perhaps because of the assumption that
> : people know all about them because of shell traditions.
> 
>    Probably.
> 
>    They seem adequately covered in perldata.pod.

Although you have to *find* the durned things first.  Which requires
that you realize this is 'data' instead of an operator or function.
And if you do a search, you'd better remember that `-' or you'll get
nada.
 
>    What is missing there?

I think we need the PSI::ESP module for perldoc too.  :-)
 
> : For example
> : it might be logical to mention them in  the section of perlop on
> : quote and quote-like operators?
> 
>    I agree.

At least a reference to perldata would be nice.  Like the reference
to the perlop manpage for m// and s/// and tr/// and the generalized
quotes.
 
-- 
David Cassell, OAO                               
cassell@mail.cor.epa.gov
Senior Computing Specialist                          phone: (541)
754-4468
mathematical statistician                              fax: (541)
754-4716


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

Date: Fri, 16 Apr 1999 15:23:51 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Need info on Perl vs. VB for manager persuasion
Message-Id: <7o28f7.aoa.ln@magna.metronet.com>

Keith Phillips (kdp@nntp.hom.net) wrote:
: The IT manager at my company wants me to come up with a Perl-
: vs-VB point sheet.  I checked the FAQs, but came up empty.  Is
: there already a document somewhere that compares Perl to VB?

: [ ... or do I need to write one and post it for all to use? :-) ]


   see:          http://www.perl.org/advocacy/


   What happened to the Cheim story that used to be there?

   That was a powerful one...


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 16 Apr 1999 15:04:33 -0700
From: Steven May <stevenjm@olywa.net>
Subject: Re: Need info on Perl vs. VB for manager persuasion
Message-Id: <3717B3F1.176DA01F@olywa.net>



David Cassell wrote:
> 
> Keith Phillips wrote:
> >
> > The IT manager at my company wants me to come up with a Perl-
> > vs-VB point sheet.  I checked the FAQs, but came up empty.  Is
> > there already a document somewhere that compares Perl to VB?
> 
> I suspect that there are 765.4 such documents out there on the web,
> and 765.399999 of them are incorrect and/or out of date.  Be
> wary of advice from strangers when the advice cannot be verified
> [including this post, of course].
> 
> > [ ... or do I need to write one and post it for all to use? :-) ]
> 
> Yes.
> 
> I work with a hacker who has programmed in VB (among several other
> languages), and he is quite frustrated with the rate at which the
> core language has changed over time.  That seems like a serious
> drawback to me.
> 

I used to work a little with VB (last version on the shelf is VB 4.0)
and the reason above is one of the things that soured me on it.  The
other was a percieved lack of proper documentation.  I'd fight a routine
for hours (sometimes days) before discovering that some method or
property I was attempting to use had an undocumented bug that prevented
it from working as claimed. Also didn't like the idea that I HAD to do
things the way some dweeb working for M$ decided was the right way.

Very annoying.

As an interesting aside, I recently converted a VBA snippet to Perl for
a client.

Three subroutines and 50 lines of VBA code became 10 lines in Perl. 
Could have packed it down tighter, if I had maintained the
(non-existent) level of error checking and trapping in the original
'code'.

Wonder which one is easier to maintain?

Steve


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

Date: 16 Apr 1999 21:26:13 GMT
From: Captain SilverWolf <starwolf@rahul.net>
Subject: Need password HELP!!
Message-Id: <7f89tl$hj$1@samba.rahul.net>

I have been handed a job that is definitely NOT something I have done
before.  I need to make a page password accessable(sp) only.  I have not
had to work before and don't really know for sure where to start.   I do
know that I want it to be a perl cgi script if possible.  More than that,
as I said, I am not sure of.

God but I sound like the greenest of newbies with THAT line.  Oh well.

All help cheefully accepted with heartfelt thanks.

Please note that I am not posting from my usual account, so if you want
(or need) to reach me directly, my correct email addy is:
sarahj@earthling.net.

TIA

	SJS posting from a friend's account.
-- 
May the Lords of Luck and Chance be always at your side, and may your hand
always be a winner.

Captain Wolf


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

Date: 16 Apr 1999 16:15:35 -0400
From: Uri Guttman <uri@home.sysarch.com>
Subject: Re: New FAQ: How can I read in an entire file all at once?
Message-Id: <x7676wmie0.fsf@home.sysarch.com>

>>>>> "TC" == Tom Christiansen <tchrist@mox.perl.com> writes:

  TC> =head2 How can I read in an entire file all at once?

good addition to the FAQ.

  TC> That temporarily unders your record separator, and will automatically
                           ^
                           f

  TC> close the file at block exit.  If the file is already open, just use this:
                                          
  TC>     $var = do { local $/; <INPUT> };      

i would mention @lines = <INPUT> as an alternative for reasonable size
files. you don't mention in the title whether this is a scalar or list
context. the loop method is line by line processing which the array
slurp will allow for too. also mentioning `cat` in a list context would
be more complete.

uri

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


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

Date: 16 Apr 1999 14:26:24 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Re: New FAQ: How can I read in an entire file all at once?
Message-Id: <37179cf0@cs.colorado.edu>

 [courtesy cc of this posting sent to cited author via email]

In comp.lang.perl.misc, Uri Guttman <uri@home.sysarch.com> writes:
:i would mention @lines = <INPUT> as an alternative for reasonable size
:files. you don't mention in the title whether this is a scalar or list
:context. the loop method is line by line processing which the array
:slurp will allow for too. also mentioning `cat` in a list context would
:be more complete.

Try this.

--tom

=head2 How can I read in an entire file all at once?

The customary Perl approach for processing all the lines in a file is to
do so one line at a time:

    open (INPUT, $file) 	|| die "can't open $file: $!";
    while (<INPUT>) {
	chomp;
	# do something with $_
    } 
    close(INPUT)	    	|| die "can't close $file: $!";

This is tremendously more efficient than reading the entire file into
memory as an array of lines and then processing it one element at a time,
which is often -- if not almost always -- the wrong approach.  Whenever
you see someone do this:

    @lines = <INPUT>;

You should think long and hard about why you need everything loaded
at once.  It's just not a scalable solution.  You might also find it
more fun to use the the standard DB_File module's $DB_RECNO bindings,
which allow you to tie an arrya to a file so that accessing an element
the array actually accesses the corresponding line in the file.

On very rare occasion, you may have an algorithm that demands that
the entire file be in memory at once as one scalar.  The simplest solution
to that is:

    $var = `cat $file`;

Being in scalar context, you get the whole thing.  In list context,
you'd get a list of all the lines:

    @lines = `cat $file`;

This tiny but expedient solution is neat, clean, and portable to all
systems that you've bothered to install decent tools on, even if you are
a Prisoner of Bill.  For those die-hards PoBs who've paid their billtax
and refuse to use the toolbox, or who like writing complicated code for
job security, you can of course read the file manually.

    {
	local(*INPUT, $/);
	open (INPUT, $file) 	|| die "can't open $file: $!";
	$var = <INPUT>;
    }

That temporarily undefs your record separator, and will automatically 
close the file at block exit.  If the file is already open, just use this:

    $var = do { local $/; <INPUT> };

-- 
"Software Engineers are like economists." --Rob Pike


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

Date: Fri, 16 Apr 1999 12:22:18 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: Open an THML file but don't display it
Message-Id: <q3o7f7.6la.ln@magna.metronet.com>

Kevin (mpajot@club-internet.fr) wrote:

: I would like to write a perl script which opens an URL but doesn't send it
: to the browser. It's just to analyze the contain of this file.
: I suppose there is just a function that makes the job...
: Can you help me please ?


  use LWP::Simple;


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: 16 Apr 1999 14:51:31 -0700
From: Tom Christiansen <tchrist@mox.perl.com>
Subject: Perl Power Tools status update
Message-Id: <3717a2d3@cs.colorado.edu>

The Perl Power Tools project has been recently updated
with yet more tools.  Check out

    http://language.perl.com/ppt/

For details.

--tom
-- 
    In the long run, every program becomes rococo, and then rubble.
                    -- Alan Perlis


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

Date: Fri, 16 Apr 1999 21:55:43 +0100
From: Paul Breslaw <paul@breslaw.demon.co.uk>
Subject: Sorting question
Message-Id: <3717A3CF.41C67EA6@breslaw.demon.co.uk>

Suppose I've got the following data

my %data = (
    fred => { age => 20 },
    bill => { age => 30 },
    andy => { age => 35 },
    dick => { age => 30 },
    nora => { age => 20 },
    toni => { age => 35 },
    bert => { age => 40 },
    jane => { age => 20 }
);

and I want to sort the people by age, and within each age group sort
the names alphabetically.  The following would seem to be the right
approach:-

foreach my $p (sort { $data{$a}->{age} <=> $data{$b}->{age} } sort keys
%data) {
    print "$p  $data{$p}->{age}\n";
}

This worked fine on Linux, 

fred  20
jane  20
nora  20
bill  30
dick  30
andy  35
toni  35
bert  40

but on SunOS and Solaris produced

fred  20
nora  20
jane  20
dick  30
bill  30
andy  35
toni  35
bert  40

So even if qsort(3) is different on the OS's

   - Why does the second sort muck up the results of the first?
   - What is the correct way to solve my problem portably?

Thanks for any hints.

Paul Breslaw.

---
Paul Breslaw                       |  tel:    +44 1342 823194
Old Shalesbrook, Shalesbrook Lane  |  fax:    +44 1342 825963
Forest Row, E. Sussex RH18 5LS     |  e-mail: paul@breslaw.demon.co.uk
England                            |


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

Date: Fri, 16 Apr 1999 14:29:49 -0700
From: lr@hpl.hp.com (Larry Rosler)
Subject: Re: Sorting question
Message-Id: <MPG.11814ba4ae6f3bc89898cb@nntp.hpl.hp.com>

[Posted and a courtesy copy mailed.]

In article <3717A3CF.41C67EA6@breslaw.demon.co.uk> on Fri, 16 Apr 1999 
21:55:43 +0100, Paul Breslaw <paul@breslaw.demon.co.uk> says...
> Suppose I've got the following data
> 
> my %data = (
>     fred => { age => 20 },
>     bill => { age => 30 },
>     andy => { age => 35 },
>     dick => { age => 30 },
>     nora => { age => 20 },
>     toni => { age => 35 },
>     bert => { age => 40 },
>     jane => { age => 20 }
> );
> 
> and I want to sort the people by age, and within each age group sort
> the names alphabetically.  The following would seem to be the right
> approach:-
> 
> foreach my $p (sort { $data{$a}->{age} <=> $data{$b}->{age} } sort keys
> %data) {
>     print "$p  $data{$p}->{age}\n";
> }

<SNIP> different ordering of identical sort keys on different systems

>    - Why does the second sort muck up the results of the first?
>    - What is the correct way to solve my problem portably?

As you have discovered, sorting algorithms make no guarantees about 
ordering of identical keys (unless the sort is called 'stable' which 
means it guarantees to preserve the input order for identical keys).  
You have to do it yourself, in one 'sort' rather than two.

  foreach my $p (sort { $data{$a}->{age} <=> $data{$b}->{age}
                                   || $a cmp $b } keys %data) {
      print "$p  $data{$p}->{age}\n";
  }

-- 
(Just Another Larry) Rosler
Hewlett-Packard Company
http://www.hpl.hp.com/personal/Larry_Rosler/
lr@hpl.hp.com


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

Date: Fri, 16 Apr 1999 15:53:23 -0600
From: "Tim Chambers" <tbc@col.hp.com>
Subject: which way is better to reap child processes?
Message-Id: <7f8bkl$bph$1@nonews.col.hp.com>

I have a subroutine that forks an arbitrary number of
processes to do work in parallel. I want to wait for them
all, then gather their output and return it.

I'm attaching two versions: DoCmdsRetOutput1 and
DoCmdsRetOutput2. I'm wondering if either of these reaping
algorithms is preferable. Each is commented as follows:

############################################################
# ALGORITHM 1: seems to me we could wait in any order -- all
# have to finish before we'll ever get through the loop
############################################################

############################################################
# ALGORITHM 2: block waiting for any process; reap as many
# as are waiting
############################################################

Of course, if there's a way preferable to either of my
approaches, I'd appreciate correction, too :-).  I'm leaning
toward algorithm 2 because I'm afraid algorithm 1 might miss
processes that die early if I happen to be waiting for a
long process.

I've read the PERL COOKBOOK section "Avoiding Zombie
Processes on pp. 590-593, I know about Proc::Simple, and I
also read the perlipc man page re. Signals. In the Cookbook,
tchrist talks about setting up signal handlers to reap, but
I don't think that applies to my need -- I want to
syncronize the completion of all the children so I can
return all their results together.

<>< Tim Chambers               || tbc@col.hp.com (e-mail)
Software Design Engineer       || 719.590.5570 (Office phone)
Hewlett-Packard Company        || 719.590.2251 (Fax)
http://www.geocities.com/Athens/3680/ (Personal Web)
The opinions and URL recommendations stated here are my own
and do not necessarily represent those of Hewlett-Packard.

------------------------- cut here -------------------------
#!/usr/bin/perl -w

$DOCMDS_PREFIX = "/tmp/dcro";
$NO_RC_YET = "no RC yet"; # could be any string (tbc, 04/16/99)

$::SIG{INT} = 'IGNORE';

sub _intHndlr(@)
{
    $_interrupt = 1;
}

sub File2Array($)
{
    my $filespec = shift;
    my @newAr = ();

    open AR_SRC_FILE,"<$filespec" ||
      die "File2Array(): unable to read [$filespec]: $!";

    #  load our data file into the array
    @newAr = <AR_SRC_FILE>; # grab all lines of file

    #  close our data file
    close AR_SRC_FILE ||
      die "File2Array(): unable to close [$filespec]: $!";

    chomp @newAr;
    my $lineCt = @newAr;

    return @newAr;
}

sub DoCmdsRetOutput1(@@@)
{
    local *cmdAr = shift;
    my $savedIntHnldr = $::SIG{INT};
    my %cmd2pidHs;

    $::SIG{INT} = '_intHndlr'; # override

    local *stdoutAr = shift;
    local *stderrAr = shift;

    my $rc = 0;
    my $cmdStr;

    foreach $cmdStr (@cmdAr) {
        unless ($pid = fork) {
            # we're the child, so do the work
            my $retCode = 0;

            # create a unique prefix for each command -- note coupling in
            # parent outside this loop (tbc, 04/15/99)
            my $stdoutFname = "${DOCMDS_PREFIX}.$$.out";
            my $stderrFname = "${DOCMDS_PREFIX}.$$.err";

            # Add our output files to desired command -- parent will
            # clean up. Run in sub shell so all output is captured in
            # output files.
            #
            $cmdStr = "/bin/posix/sh -c '$cmdStr' " .
              "1>$stdoutFname 2>$stderrFname";
     $retCode = system($cmdStr);

            exit $retCode; # child is done
        }

        if ($pid) {
            $cmd2pidHs{$cmdStr} = $pid;
            print "DoCmdsRetOutput1: will wait for [$pid]\n";
        } else {
            # This might help debugging, but might as well keep going; try
            # all requested work -- they're all independent.  The failed
            # call should have emitted its own meaningful error message.
            # (tbc, 04/15/99)
            print
       "ERROR: DoCmdsRetOutput1: ",
       "detected a problem trying to run '$_' ($!)\n";
            $rc++;
        }
    }

    @stdoutAr = @stderrAr = (); # init arrays
    my ($cmdRet, $waitRet, $stdoutFname, $stderrFname);
    for (keys %cmd2pidHs) {
        $pid = $cmd2pidHs{$_};
 ######################################################################
 # ALGORITHM 1: seems to me we could wait in any order -- all have
 # to finish before we'll ever get through the loop (tbc, 04/15/99)
 ######################################################################
        $waitRet = waitpid $pid, 0;
        if ($waitRet == $pid) {
            # parse return code; done thoroughly by swengCommon::DoCmd()
            # (tbc, 04/15/99)
            $cmdRet = $? >> 8;
            print "$pid done\n";
            if ($cmdRet != 0) {
                print "DoCmdsRetOutput1: '$_' FAILED, rc=[$cmdRet]\n";
                $rc++;
            }
            $stdoutFname = "${DOCMDS_PREFIX}.${pid}.out";
            $stderrFname = "${DOCMDS_PREFIX}.${pid}.err";
            if (-s $stdoutFname) {
                push @stdoutAr, File2Array($stdoutFname);
            }
            if (-s $stderrFname) {
                push @stderrAr, File2Array($stderrFname);
            }
            # clean up
            unlink $stdoutFname;
            unlink $stderrFname;
        } else {
            # not sure how this could happen, but say something about it
            print
       "DoCmdsRetOutput1: cmd=[$_], expected [$pid], got [$waitRet]\n";
        }
    }
    return $rc; # we're done!
}

sub DoCmdsRetOutput2(@@@)
{
    local *cmdAr = shift;
    my $savedIntHnldr = $::SIG{INT};
    my %cmd2pidHs;

    $::SIG{INT} = '_intHndlr'; # override

    local *stdoutAr = shift;
    local *stderrAr = shift;

    my $rc = 0;
    my $cmdStr;

    foreach $cmdStr (@cmdAr) {
        unless ($pid = fork) {
            # we're the child, so do the work
            my $retCode = 0;

            # create a unique prefix for each command -- note coupling in
            # parent outside this loop (tbc, 04/15/99)
            my $stdoutFname = "${DOCMDS_PREFIX}.$$.out";
            my $stderrFname = "${DOCMDS_PREFIX}.$$.err";

            # Add our output files to desired command -- parent will
            # clean up. Run in sub shell so all output is captured in
            # output files.
            #
            $cmdStr = "/bin/posix/sh -c '$cmdStr' " .
              "1>$stdoutFname 2>$stderrFname";
     $retCode = system($cmdStr);

            exit $retCode; # child is done
        }

        if ($pid) {
            $cmd2pidHs{$cmdStr} = $pid;
            print "DoCmdsRetOutput2: will wait for [$pid]\n";
        } else {
            # This might help debugging, but might as well keep going; try
            # all requested work -- they're all independent.  The failed
            # call should have emitted its own meaningful error message.
            # (tbc, 04/15/99)
            print
       "ERROR: DoCmdsRetOutput2: ",
       "detected a problem trying to run '$_' ($!)\n";
            $rc++;
        }
    }

    # now that we've forked all commands, we wait
    my %pid2rcHs;
    my $total = keys %cmd2pidHs;
    my $reapCount = 0;
    # initialize our hash -- bug fix (tbc, 04/16/99)
    for (values %cmd2pidHs) { $pid2rcHs{$_} = $NO_RC_YET; }
    #
    # Reap all children as they finish. Thought about reaping in a signal
    # handler, per PERL COOKBOOK, p.591-592. Doing it this way instead
    # because I need a synchronous interface.  Also allow interrupt.
    # (tbc, 04/16/99)
    while (($reapCount < $total) && (!$_interrupt)) {
 ######################################################################
 # ALGORITHM 2: block waiting for any process; reap as many as are
 # waiting
 ######################################################################
        while (($pid = waitpid(-1, 0)) > 0) {
            if (exists $pid2rcHs{$pid}) {
                # should never happen, but say something
                if ($pid2rcHs{$pid} ne $NO_RC_YET) {
                    print
        "INTERNAL ERROR: \$pid2rcHs{$pid}=[$pid2rcHs{$pid}]\n";
                }
                $pid2rcHs{$pid} = $?;
                $reapCount++;
                print "reaped child $pid\n";
            } else {
                print "ignoring extranneous process $pid\n";
            }
        }
    }

    # restore
    $::SIG{INT} = $savedIntHnldr;

    if ($_interrupt) {
        # TBD: I'm not sure how this interrupt feature will be used, but for
        # now, treat it as a request for additional debug before aborting.
        # It's also a pattern for any other interrupt override behavior we
        # might want to add to our system later. (tbc, 04/16/99)
 print
   "detected interrupt; ",
   "reap count = $reapCount, total = $total\n";
 for (keys %cmd2pidHs) {
     print "cmd '$_' PID=[$cmd2pidHs{$_}]\n";
 }
 print "Reaped the following:\n";
 for (keys %pid2rcHs) {
     print"\tPID $_ \$?=[$pid2rcHs{$_}]\n";
 }

        # and die
        die "Aborting";
    }

    @stdoutAr = @stderrAr = (); # init arrays
    my ($cmdRet, $waitRet, $stdoutFname, $stderrFname);
    for (keys %cmd2pidHs) {
        $pid = $cmd2pidHs{$_};
        if (exists $pid2rcHs{$pid}) {
            # parse return code; done thoroughly by swengCommon::DoCmd()
            # (tbc, 04/16/99)
            $cmdRet = $pid2rcHs{$pid} >> 8;
            print "$pid done\n";
            if ($cmdRet != 0) {
                print "DoCmdsRetOutput2: '$_' FAILED, rc=[$cmdRet]\n";
                $rc++;
            }
            $stdoutFname = "${DOCMDS_PREFIX}.${pid}.out";
            $stderrFname = "${DOCMDS_PREFIX}.${pid}.err";
            if (-s $stdoutFname) {
                push @stdoutAr, File2Array($stdoutFname);
            }
            if (-s $stderrFname) {
                push @stderrAr, File2Array($stderrFname);
            }
            # clean up
            unlink $stdoutFname;
            unlink $stderrFname;
        } else {
            # not sure how this could happen, but say something about it
            print
       "INTERNAL ERROR: DoCmdsRetOutput2: no reap?! ",
       "cmd=[$_], PID=[$pid]\n";
        }
    }
    return $rc; # we're done!
}

############################################################################
##
# this is the test
for (1, 2, 3) {
    push @cmdAr, "/usr/bin/echo \${PPID}, \$\$ $_;/usr/bin/sleep $_";
}
print "@cmdAr\n";
$rc1 = DoCmdsRetOutput1(\@cmdAr, \@out1,\@err1);
$rc2 = DoCmdsRetOutput2(\@cmdAr, \@out2,\@err2);
$, = $\ = "\n";
print "DoCmdsRetOutput1:", "stdout:", @out1, "stderr:", @err1, "rc=[$rc1]";
print "DoCmdsRetOutput2:", "stdout:", @out2, "stderr:", @err2, "rc=[$rc2]";





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

Date: Fri, 16 Apr 1999 15:33:31 -0400
From: tadmc@metronet.com (Tad McClellan)
Subject: Re: why won't this statement work @array=<*.*>
Message-Id: <ba38f7.rpa.ln@magna.metronet.com>

George (dscapin@harris.com) wrote:
: I am trying to put files in the current directory into an array.  When I
: use the following statement on my machine running xwin32 server, it
: works:

: @array = <*.*>

: Now, when I put the perlscript on the server this statement doesn't
: work.  The server is an NT server.  It doesn't work because the number
: of elements is 0.  I am looking for a code snipplet that will load the
: filenames into the array.  Can someone help me?


   opendir(DIR, '.') || die "could not open current directory  $!";
   @array = readdir(DIR);
   closedir(DIR);


--
    Tad McClellan                          SGML Consulting
    tadmc@metronet.com                     Perl programming
    Fort Worth, Texas


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

Date: Fri, 16 Apr 1999 15:52:17 -0500
From: danbeck@scott.net (Daniel Beckham)
Subject: Re: Would anyone care to teach me perl?
Message-Id: <MPG.11815efacabb238698969d@news.idt.net>

HA!  My fellow (non programmer) co-workers think I'm a bit goofy with my 
@array of ORA books.  I have 11 here and about 6 at home...  Best 
references in the world.

In article <37178DEB.BCBEF3D@mail.cor.epa.gov>, cassell@mail.cor.epa.gov 
says...
> KC wrote:
> > 
> > Ala Qumsieh wrote:
> > > Why? Don't you know how to read books? It's very simple. In English,
> > > words go from left to write, but you knew that already.
> > > Pages can be flipped. A book is made up of one or more pages. Words in
> > > books look almost exactly like words in email messages. They can be
> > > read too.
> > 
> > Book?? You mean a non-volitale storage media ;-)
> 
> I have a 4-year-old who likes animal pictures.  My O'Reilly books
> therefore constitute a *very* volatile storage medium.  :-)
> 
> David, who is eyeing your spelling but is not going there today...
> 


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

Date: Fri, 16 Apr 1999 16:01:44 -0400
From: Lanny Gilbert <lanny.gilbert@bellsouth.net>
Subject: Re: zipped perlman
Message-Id: <37179728.7F03018A@bellsouth.net>

You can "untar" the perl man file using the WinZip utility, which you
probably
already have. Just make sure that if it's a tar file that the file has a
".tar" extension
and if it's a zipped tar file, it has the ".tar.Z" extension.

Lanny Gilbert

Jeff Thies wrote:

>   I'm a windows user and would like to have the perl man local. Is there
> a zipped version? I can find the tarred version.
>
> Jeff



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

Date: 16 Apr 1999 21:32:51 GMT
From: davewal@echo.corp.sgi.com (David Walford)
Subject: Re: { } question/problem
Message-Id: <7f8aa3$iok$1@murrow.corp.sgi.com>


I am not sure the information below is helping me or maybe I am not
understanding how it is applied.

I am not trying to assign a variable with a variable.
I have a bunch of arrays with titles like "name_array, date_array, time_array".
I would like to use a variable to define the first part of the arrays title for
a subroutine to use the appropriate array.

This was my example:
for (sort keys %${tag}_array )  <-- But this doesn't work.

Thanks
David






In article <3717848d@cs.colorado.edu>, Tom Christiansen <tchrist@mox.perl.com>
writes:
|>  [courtesy cc of this posting sent to cited author via email]
|> 
|> In comp.lang.perl.misc, davewal@echo.corp.sgi.com (David Walford) writes:
|> :How do I call up an array that has a name which is built with a variable?
|> 
|> You don't.  Stop using the package symbol table as an ersatz hash.
|> Use your own.
|> 
|> --tom
|> 
|> =head2 How can I use a variable as a variable name?
|> 
|> Beginners often think they want to have a variable contain the name
|> of a variable.
|> 
|>     $fred    = 23;
|>     $varname = "fred";
|>     ++$$varname;         # $fred now 24
|> 
|> This works I<sometimes>, but it is a very bad idea for two reasons.
|> 
|> The first reason is that they I<only work on global variables>.
|> That means above that if $fred is a lexical variable created with my(),
|> that the code won't work at all: you'll accidentally access the global
|> and skip right over the private lexical altogether.  Global variables
|> are bad because they can easily collide accidentally and in general make
|> for non-scalable and confusing code.
|> 
|> Symbolic references are forbidden under the C<use strict> pragma.
|> They are not true references and consequently are not reference counted
|> or garbage collected.
|> 
|> The other reason why using a variable to hold the name of another
|> variable a bad idea is that the question often stems from a lack of
|> understanding of Perl data structures, particularly hashes.  By using
|> symbolic references, you are just using the package's symbol-table hash
|> (like C<%main::>) instead of a user-defined hash.  The solution is to
|> use your own hash or a real reference instead.
|> 
|>     $fred    = 23;
|>     $varname = "fred";
|>     $USER_VARS{$varname}++;  # not $$varname++
|> 
|> There we're using the %USER_VARS hash instead of symbolic references.
|> Sometimes this comes up in reading strings from the user with variable
|> references and wanting to expand them to the values of your perl
|> program's variables.  This is also a bad idea because it conflates the
|> program-addressable namespace and the user-addressable one.  Instead of
|> reading a string and expanding it to the actual contents of your program's
|> own variables:
|> 
|>     $str = 'this has a $fred and $barney in it';
|>     $str =~ s/(\$\w+)/$1/eeg;		  # need double eval
|> 
|> Instead, it would be better to keep a hash around like %USER_VARS and have
|> variable references actually refer to entries in that hash:
|> 
|>     $str =~ s/\$(\w+)/$USER_VARS{$1}/g;   # no /e here at all
|> 
|> That's faster, cleaner, and safer than the previous approach.  Of course,
|> you don't need to use a dollar sign.  You could use your own scheme to
|> make it less confusing, like bracketed percent symbols, etc.
|> 
|>     $str = 'this has a %fred% and %barney% in it';
|>     $str =~ s/%(\w+)%/$USER_VARS{$1}/g;   # no /e here at all
|> 
|> Another reason that folks sometimes think they want a variable to contain
|> the name of a variable is because they don't know how to build proper
|> data structures using hashes.  For example, let's say they wanted two
|> hashes in their program: %fred and %barney, and to use another scalar
|> variable to refer to those by name.
|> 
|>     $name = "fred";
|>     $$name{WIFE} = "wilma";     # set %fred
|> 
|>     $name = "barney";           
|>     $$name{WIFE} = "betty";	# set %barney
|> 
|> This is still a symbolic reference, and is still saddled with the
|> problems enumerated above.  It would be far better to write:
|> 
|>     $folks{"fred"}{WIFE}   = "wilma";
|>     $folks{"barney"}{WIFE} = "betty";
|> 
|> And just use a multilevel hash to start with.
|> 
|> The only times that you absolutely I<must> use symbolic references are
|> when you really must refer to the symbol table.  This may be because it's
|> something that can't take a real reference to, such as a format name.
|> Doing so may also be important for method calls, since these always go
|> through the symbol table for resolution.
|> 
|> In those cases, you would turn off C<strict 'refs'> temporarily so you
|> can play around with the symbol table.  For example:
|> 
|>     @colors = qw(red blue green yellow orange purple violet);
|>     for my $name (@colors) {
|>         no strict 'refs';  # renege for the block
|>         *$name = sub { "<FONT COLOR='$name'>@_</FONT>" };
|>     } 
|> 
|> All those functions (red(), blue(), green(), etc.) appear to be separate,
|> but the real code in the closure actually was compiled only once.
|> 
|> So, sometimes you might want to use symbolic references to directly
|> manipulate the symbol table.  This doesn't matter for formats, handles, and
|> subroutines, because they are always global -- you can't use my() on them.
|> But for scalars, arrays, and hashes -- and usually for subroutines --
|> you probably want to use hard references only.
|> -- 
|>     Q. Why is this so clumsy?
|>     A. The trick is to use Perl's strengths rather than its weaknesses.
|>             --Larry Wall in <8225@jpl-devvax.JPL.NASA.GOV>

-- 
--------------------------------------------------------------
 David M. Walford           | email: davewal@corp.sgi.com
 RealityCenter Tech. Engr.  | m/s: 06U-122 
 Silicon Graphics, Inc.     | voice: 650-933-6451 
 Corporate Briefing Center  | fax: 650-932-6451 


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

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

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