[18341] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 509 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Mar 16 21:06:08 2001

Date: Fri, 16 Mar 2001 18:05:10 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <984794710-v10-i509@ruby.oce.orst.edu>
Content-Type: text

Perl-Users Digest           Fri, 16 Mar 2001     Volume: 10 Number: 509

Today's topics:
    Re: -w and use strict; (Tad McClellan)
    Re: -w and use strict; (Tad McClellan)
    Re: -w and use strict; <webmaster@webdragon.munge.net>
    Re: -w and use strict; <flavell@mail.cern.ch>
    Re: -w and use strict; <bmb@ginger.libs.uga.edu>
        Client IP <R.W.SpernaWeiland@student.utwente.nl>
    Re: Client IP <R.W.SpernaWeiland@student.utwente.nl>
        DBM Q! <hernux@etherac.com.ar>
        Didn't work. (Jim Kroger)
    Re: Doesnt work (Martien Verbruggen)
    Re: Doesnt work (John Joseph Trammell)
    Re: Doesnt work (Martien Verbruggen)
    Re: FAQ 7.12:   What's a closure? (Ilya Zakharevich)
    Re: how can I restart a regex within a substitution wit <krahnj@acm.org>
    Re: HTTP Client Question (Tad McClellan)
    Re: HTTP Client Question <flavell@mail.cern.ch>
    Re: Memory and Perl <webmaster@webdragon.munge.net>
        Memory Usage <SPAMREMOVEcharleswarner@bigfoot.com>
    Re: Memory Usage (Ilya Zakharevich)
    Re: Memory Usage <godzilla@stomp.stomp.tokyo>
        My Safe Backticks attempt - separate stdout & stderr co <sidi@angband.org>
    Re: Perl 4 (Martien Verbruggen)
    Re: PERL and ASP <nospam@nospam.net>
    Re: Perl Version Question <webmaster@webdragon.munge.net>
    Re: Quick struct question in perl. example code inc (Tad McClellan)
    Re: Subroutine in separate files <godzilla@stomp.stomp.tokyo>
        ZPT, a next-generation template technology <hamish_lawson@btinternet.com>
        Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)

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

Date: Fri, 16 Mar 2001 15:16:09 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: -w and use strict;
Message-Id: <slrn9b4t49.9k1.tadmc@tadmc26.august.net>

Kevin Lacquement <klacquement@syscor.com> wrote:
>>>>>> "LM" == Lou Moran <lmoran@wtsg.com> writes:

[ snip: -w and use strict ]

>    LM> My questions are:
>
>    LM> Do you remove those once your script works as expected and is
>    LM> unlikely to be changed?
>        ^^^^^^^^^^^^^^^^^^^^^^


No, I never take either one out.

Note that warnings can be triggered by _data_. 

Is your data also never going to change?   <grin>


>    LM> Are there good reasons not to use those things?


No, if you are getting paid for it.

Yes, if you are playing around.


>You're writing a cheap hack or school assignment?


My take is that it is unethical to accept payment for Perl
programming without warnings and strictures enabled.

I gave immediate zeros on school assignments that left them out,
when I was privileged to have such power.



Me, quoting "me", as portrayed by Bernard:

   "Don't forget to enable warnings and strictures even when 
    you're not writing in Perl. It's *that* important."


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 16 Mar 2001 15:17:01 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: -w and use strict;
Message-Id: <slrn9b4t5t.9k1.tadmc@tadmc26.august.net>

Mona Wuerz <wuerz@yahoo.com> wrote:

>should I leave the -w and use strict in
>the working copy?


Yes.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: 17 Mar 2001 00:23:40 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: -w and use strict;
Message-Id: <98uaqc$h8a$4@216.155.32.136>

In article <x7ae6l79td.fsf@home.sysarch.com>, Uri Guttman 
<uri@sysarch.com> wrote:

 | BTW, strict is a per file (compile time, remember) feature. it has to be
 | in every module you write or use. -w is a global flag and needs only to
 | be set once. the new 5.6 use warnings is file scoped like strict and has
 | to be in each file.

That's good to know.. I'm glad I was stumbling around in here just 
catching up and saw this before the news server I have (with it's 
perilously short (dammit!) holding time for usenet posts) expired it.

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Sat, 17 Mar 2001 01:37:01 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: -w and use strict;
Message-Id: <Pine.LNX.4.30.0103170134220.14900-100000@lxplus003.cern.ch>

On Fri, 16 Mar 2001, Tad McClellan wrote:

> Mona Wuerz <wuerz@yahoo.com> wrote:
>
> >should I leave the -w and use strict in
> >the working copy?
>
> Yes.

But if it's a CGI script, take care to send the warnings to the script
owner, the admin, or the log, rather than to the prospective hacker,
who will no doubt be looking for exploitable weaknesses in one's
programming style.




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

Date: Fri, 16 Mar 2001 20:26:29 -0500
From: Brad Baxter <bmb@ginger.libs.uga.edu>
Subject: Re: -w and use strict;
Message-Id: <Pine.A41.4.21.0103162024270.9068-100000@ginger.libs.uga.edu>

On Fri, 16 Mar 2001, Tad McClellan wrote:
> 
> Me, quoting "me", as portrayed by Bernard:
> 
>    "Don't forget to enable warnings and strictures even when 
>     you're not writing in Perl. It's *that* important."

LOL.  When your not writing in Perl, that's known as diplomacy.

:-)

Brad



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

Date: Sat, 17 Mar 2001 01:31:59 +0100
From: "Robbert" <R.W.SpernaWeiland@student.utwente.nl>
Subject: Client IP
Message-Id: <98ub2l$fth$1@dinkel.civ.utwente.nl>



Hey all,

OK, this is the case:
I have a HTML form on my site, which sends the information, given by the
visitor, to a perl script on my server.
Now, I once knew how to get the IP address of the visitor into a variable in
the perl script, but I dont remember how....
Could anybody help me out here??

Thanks at advance,
Robbert






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

Date: Sat, 17 Mar 2001 01:40:18 +0100
From: "Robbert" <R.W.SpernaWeiland@student.utwente.nl>
Subject: Re: Client IP
Message-Id: <98ubid$g91$1@dinkel.civ.utwente.nl>

Never mind, I remembered already....

"Robbert" <R.W.SpernaWeiland@student.utwente.nl> wrote in message
news:98ub2l$fth$1@dinkel.civ.utwente.nl...
>
>
> Hey all,
>
> OK, this is the case:
> I have a HTML form on my site, which sends the information, given by the
> visitor, to a perl script on my server.
> Now, I once knew how to get the IP address of the visitor into a variable
in
> the perl script, but I dont remember how....
> Could anybody help me out here??
>
> Thanks at advance,
> Robbert
>
>
>
>




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

Date: Fri, 16 Mar 2001 20:09:11 -0300
From: "Hernux" <hernux@etherac.com.ar>
Subject: DBM Q!
Message-Id: <98u83i$ahb$1@taliesin.netcom.net.uk>

Hi everyone,

is there a way to control a file lifetime in a dbm?

example:
--------------------
my %car=();
dbmopen (%car, "car_data", 0666);
%car = (   'make'  => 'Nissan',
                 'model' => 'Maxima',
                 'year'  => '1997',
                 'color' => 'evergreen'
        );
dbmclose (%car);
--------------------
and I want that file car_data.db only exists for the next 24 Hs.

Thankz




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

Date: Fri, 16 Mar 2001 19:19:06 -0500
From: minorseventhSPAMBLOCK@earthlink.net (Jim Kroger)
Subject: Didn't work.
Message-Id: <minorseventhSPAMBLOCK-1603011919060001@tritone.csbmb.princeton.edu>

Hi Michael, it didn't work.

In article <3AB27201.FC3B5B94@home.com>, Michael Carman
<mjcarman@home.com> wrote:


> 
> s/^\s+//;
> s/\s+$//;
> 
> to remove leading and trailing whitespace.
> 
> -mjc



I changed 

chomp(@subjects = `cat subNames`);
foreach (@subjects) {
   chomp($_);
   }


to 


chomp(@subjects = `cat subNames`);
foreach (@subjects) {
   s/^\s+//;
   s/\s+$//;
   }


But the tab character at the end of each subject item is still there.
Sorry if I'm misunderstanding. 

I only have "Learning Perl" and it doesn't explain how to change $/.  I'm
afraid I have little luck with the man pages, they are pretty impenetrable
to me.

Thanks
Jim


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

Date: Sat, 17 Mar 2001 11:45:10 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Doesnt work
Message-Id: <slrn9b5csm.9vo.mgjv@martien.heliotrope.home>

On Fri, 16 Mar 2001 17:16:25 GMT,
	John Joseph Trammell <trammell@bayazid.hypersloth.net> wrote:
> On Fri, 16 Mar 2001 17:08:51 GMT, Kalle Anka <kalle@tvettsvamp.a.se> wrote:
>> I know that the files math, but nothing prints out!
>> For example: $filename is
>> someone@somewere.com <br>
>> someone2@somewere.com <br>
>> someone3@somewere.com <br>
> 
> Spaces count for something!  "abc" != "a b c"...

\begin{pedantry}

and != isn't the same as ne, on this group :)

"abc" ne "a b c"

If you try it, you'll find that in Perl, 

"abc" == "a b c" 

is actually a true expression; one which causes warnings, but
nonetheless true.

\end{pedantry}

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Sat, 17 Mar 2001 01:03:06 GMT
From: trammell@bayazid.hypersloth.net (John Joseph Trammell)
Subject: Re: Doesnt work
Message-Id: <slrn9b5bkd.jsm.trammell@bayazid.hypersloth.net>

On Sat, 17 Mar 2001 11:45:10 +1100, Martien Verbruggen wrote:
[snip]
> \begin{pedantry}
> and != isn't the same as ne, on this group :)

I was writing in English, not Perl.  Penglish?

Never did like 'ne' anyhow.  Bad FORTRAN flashbacks.



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

Date: Sat, 17 Mar 2001 12:12:59 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Doesnt work
Message-Id: <slrn9b5egr.9vo.mgjv@martien.heliotrope.home>

On Sat, 17 Mar 2001 01:03:06 GMT,
	John Joseph Trammell <trammell@bayazid.hypersloth.net> wrote:
> On Sat, 17 Mar 2001 11:45:10 +1100, Martien Verbruggen wrote:
> [snip]
>> \begin{pedantry}
>> and != isn't the same as ne, on this group :)
> 
> I was writing in English, not Perl.  Penglish?

Hmmm.. My copies of the shorter and concise OED don't contain !=.

;)

Martien
-- 
Martien Verbruggen              | Since light travels faster than
Interactive Media Division      | sound, isn't that why some people
Commercial Dynamics Pty. Ltd.   | appear bright until you hear them
NSW, Australia                  | speak?


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

Date: 17 Mar 2001 01:08:39 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: FAQ 7.12:   What's a closure?
Message-Id: <98uden$did$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Abigail
<abigail@foad.org>],
who wrote in article <slrn9b290s.p0e.abigail@tsathoggua.rlyeh.net>:
> Ilya Zakharevich (ilya@math.ohio-state.edu) wrote on MMDCCLIII September
> MCMXCIII in <URL:news:98r6if$7s2$1@charm.magnus.acs.ohio-state.edu>:
> () 
> () For me a "closure" is a thingy which
> () 
> ()  a) may be called exactly as a subroutine;
> () 
> ()  b) is *generated* by a factory;
> () 
> ()  c) (optional "efficiency edict") in the factory-generated stuff the
> ()     "code" is "shared", only the "attached data" changes.
> 
> Most people (but not me) would add
> 
>     d) There is (lexical) data attached.

Does it really matter what is the particular method of encapsulation
of data into a "subroutine + data" aggregate?  It may happen that in
all the languages which implement closures the "data" part is always
lexical.  But even if this is true, I do not think that this is a
crucial thing.

It does not influence how a closure is used.  It does not influence
what it is created for.  For me, if the syntax for creation of
closures were

  $factory = Factory->new(
	       -code => 'print shift, " --> $quantity \@ \$$price\n"';
	       -data => [ qw( quantity price ) ]
	     );
  $sub = $factory->new( quantity => 5, price => 17.99 );
  $sub->( 'limerics' );

they would still be the same "closures".

Hope this helps,
Ilya


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

Date: Fri, 16 Mar 2001 23:45:51 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: how can I restart a regex within a substitution without leaving the  /g loop?
Message-Id: <3AB2A73D.D64A3A40@acm.org>

info@java.seite.net wrote:
> 
> hi...
> 
> i want to change the starting regex of a looped substition within the
> substitution. here's a code snippet which shows what i mean...
> 
> $x="aa..b..a..b...a..a...a.#..b..a..b..b..b..a..a..b.";
> $c="a|#";
> 
> $x=~ s/($c)/if($1 eq "#") { $c="b|#"; } else { "*"
> }/ge;
> 
> ..which "should" change $x in...
> 
> **..b..*..b...*..*...*.#..*..a..*..*..*..a..a..*.
> 
> ..but of course & unfortunately doesn't work, because the variable $c is
> only
> checked once at the beginning.
> 
> is there a command which tells the regex to "recompile" the regex?
> 
> or has anybody any other ideas?

$x = "aa..b..a..b...a..a...a.#..b..a..b..b..b..a..a..b.";
$c = "a";

$x =~ s/(.)/ if ( $1 eq $c ) { "*" } elsif ( $1 eq "#" ) { $c = "b"; "#"
} else { $1 } /ge;



John
-- 
use Perl;
program
fulfillment


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

Date: Fri, 16 Mar 2001 17:45:28 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: HTTP Client Question
Message-Id: <slrn9b55s8.9k1.tadmc@tadmc26.august.net>

Al Spohn <spohn@bigfoot.com> wrote:
>In article <98tkfi$g66$1@mamenchi.zrz.TU-Berlin.DE>, 
>anno4000@lublin.zrz.tu-berlin.de says...
>> According to Bob Dilworth <avast@hortonsbay.com>:
>> > On 15 Mar 2001 15:38:51 GMT, anno4000@lublin.zrz.tu-berlin.de (Anno
><stuff snipped)
>> > Publicly "plonking" them for "jeopardy" posting serves no purpose
>> > other than, in my view, arrogance.


Whether you like it or not, people DO get plonked for Jeopardy quoting.

Silently killfiling them for all time is *easier* than announcing it.

Way over half of my killfilings are silent.

Announcing it is letting folks know that it happens, so that they
can _decide_ if they want to risk being ignored or not.


>> > intolerant.  Why waste all that energy on public humiliation when you
>> > can simply ignore the posting?


Some people say something when they see you walking around with
toilet paper stuck to your shoe, some do not say anything.

Which is nicer?


>> Because it damages the thread it appears in.  Posting style is
>> *not* a matter of personal preference.
>
>In my case it was admittedly a case of carelessness that resulted in my 
>jeopardy posting, i.e., I was using a client at the moment for which that 
>was the default, and I didn't happen to notice in time.  But I have to 
>confess to having believed that it *was* merely a preference thing 
>(certainly from a readability standpoint the argument could be made 
>either way, but I'm happy to comply with whatever standard...).  


From a purely pragmatic point of view, folks that expect to have lots
of Perl questions should probably do what it takes to avoid 
"going invisible", so as to not hurt their chances of getting
help forevermore.


>So for 
>my own edification, what is it about this practice that actually 
>*damages* the thread?


When quoted deeply by jeopardists and non-jeopardists "who said
what" and "in what order" is difficult (or impossible) to discern.


[ And it isn't only the backwards-time thing alone. Backwards
  time is nearly always accompanied by two more netiquette "no no"s:

  Quoting of the _entire_ article.

  Quoting .sigs
]


A true Jeopardist will do all three of those in each followup
they make (until they go invisible anyway).


If someone posts Jeopardy style, and no one sees it,
does it make a sound?   :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Sat, 17 Mar 2001 01:33:52 +0100
From: "Alan J. Flavell" <flavell@mail.cern.ch>
Subject: Re: HTTP Client Question
Message-Id: <Pine.LNX.4.30.0103170122440.14900-100000@lxplus003.cern.ch>

On Fri, 16 Mar 2001, Tad McClellan wrote:

> Whether you like it or not, people DO get plonked for Jeopardy quoting.

Yup, I've stopped mentioning it, most of the time.

> Silently killfiling them for all time is *easier* than announcing it.

Right: I got sick of trying to protect them from their own ignorance,
because of all the flak it caused.  Usenet has far too many posts to
be able to read them all - one has to apply some kind of criteria or
one would never get time for real life (tm).

> Announcing it is letting folks know that it happens, so that they
> can _decide_ if they want to risk being ignored or not.

Yup, that's what I used to think too.

Later I realised I couldn't be held responsible for the great unwashed
who had stumbled onto usenet without bothering to pick up a map.

> If someone posts Jeopardy style, and no one sees it,
> does it make a sound?   :-)

Not as such: but then they start a new thread, complaining about the
lack of response. This lacks the jeopardy stigma, so it becomes
visible.  Then they get flamed for whining.  All part of usenet's rich
pattern...

-- 

         This .sig only acknowledges that the message was displayed on
         the recipient's machine. There is no guarantee that the
         content has been read or understood.



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

Date: 17 Mar 2001 01:35:10 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: Memory and Perl
Message-Id: <98uf0e$rrb$1@216.155.32.136>

In article <3ab02f49$0$16231@dingus.crosslink.net>, "Collin Borrlewyn" 
<collin@crosslink.net> wrote:

 | When it comes to that, what about efficiency? Is any particular sort 
 | of loop inherently more efficient than another? There are many 
 | places where I could interchange for and foreach without trouble, 
 | for example, but is one better/more efficient? And, is there a 
 | memory-saving way to pass variables between subroutines without 
 | simply creating duplicate local variables? In short: How can I use 
 | less memory when writing my scripts?

you can use while loops to process an input file line-by-line instead of 
slurping the entire file into an array and THEN processing it.. this is 
MUCH more memory efficient. 

if this doesn't describe at least one of the things you are doing, then 
post some code :)

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Fri, 16 Mar 2001 23:12:36 GMT
From: "Charles Warner" <SPAMREMOVEcharleswarner@bigfoot.com>
Subject: Memory Usage
Message-Id: <E5xs6.2745$227.284922@newsread2.prod.itd.earthlink.net>

Hello,

I have a script that from time to time uses several hundred megabytes of
memory when normally it only uses a couple kilobytes. I would like to write
a subroutine to check when the script is using a lot of memory so I can get
some diagnostics on it.

Is there an easy way to do this?

Thanks




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

Date: 17 Mar 2001 01:10:23 GMT
From: ilya@math.ohio-state.edu (Ilya Zakharevich)
Subject: Re: Memory Usage
Message-Id: <98udhv$djd$1@charm.magnus.acs.ohio-state.edu>

[A complimentary Cc of this posting was sent to Charles Warner
<SPAMREMOVEcharleswarner@bigfoot.com>],
who wrote in article <E5xs6.2745$227.284922@newsread2.prod.itd.earthlink.net>:
> I have a script that from time to time uses several hundred megabytes of
> memory when normally it only uses a couple kilobytes. I would like to write
> a subroutine to check when the script is using a lot of memory so I can get
> some diagnostics on it.
> 
> Is there an easy way to do this?

THe latest Devel::Peek (as in 5.6.1-tobe) can do this.  The older ones
can *output* the footprint info, but do not allow the *program* to
inspect it.

Ilya


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

Date: Fri, 16 Mar 2001 17:24:11 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Memory Usage
Message-Id: <3AB2BCBB.5F4FFE4F@stomp.stomp.tokyo>

Charles Warner wrote:

(snippage)

> I have a script that from time to time uses several 
> hundred megabytes of memory when normally it only uses
> a couple kilobytes. 

> I would like to write a subroutine to check when the
> script is using a lot of memory so I can get some
> diagnostics on it.
 
> Is there an easy way to do this?


Your article is self-contradictory. You indicate knowledge
of how much memory your script uses. Clearly you already
have a method of monitoring memory usage although I am
skeptical your script only uses two kilobytes normally.

Best diagnostics is a matter of using very basic logic.
Simply replicate conditions which causes your script to
use more memory. Therein lies whatever it is you seek.

Godzilla!


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

Date: 16 Mar 2001 23:12:56 GMT
From: Chris Sidi <sidi@angband.org>
Subject: My Safe Backticks attempt - separate stdout & stderr collection
Message-Id: <98u6lo$pja$1@news-int.gatech.edu>

I'm trying to write a "safe backticks" sub like the one in perlipc except
I want to capture stdout, stderr and exec errors separately (which even
IPC::Open3 won't do).  perlipc and IPC::Open3 warn about buffering and
deadlock issues (at least if you keep switching between reading and
writing) so I wanted to see if anyone sees any problems with my attempt.

I'm wondering if there's anything I overlooked (could my while loop be
infinite?  Do I need to check for exceptions in select too?) or if I'm
checking for things that could never happen (a filehandle closing on its
own; wrapping exec in eval because I don't know if it could be fatal).  
Also do I need to use "syswrite" instead of "warn" while using
select/sysread?

Thanks!
Chris Sidi (who has grandiose visions of this going into CPAN)


#!/usr/bin/perl -w
use strict;
use IO::Handle;

my ($out_ref, $err_ref, $exec_err_ref, $did_exec, $status, $exit_val) 
    = safe_backticks(@ARGV);

if ($did_exec) {
   print <<"EOQ";
Status: $status     ExitValue: $exit_val

Output (stderr reverse-highlighted):
\e[0m$$out_ref\e[7m$$err_ref\e[0m
EOQ
} else {
   print <<"EOQ";
"@ARGV" did not execute.  Error Messages:
$$exec_err_ref
EOQ
}

sub safe_backticks {
   my ($system_command, @args) = @_;

   my $max_read_bytes = 1024;
   my $JUST_BEFORE_EXEC = "[Filehandles dupped - calling exec command next.]\n";

   #"C" is for child, "P" is for parent
   unless (pipe(C1_RDR, P1_WTR) && pipe(C2_RDR, P2_WTR) && pipe(C3_RDR, P3_WTR)) {
      die "pipe failed: $!";
   }

   #does this buy me anything, especially if I'll be execing a command in the child?
   P1_WTR->autoflush(1); P2_WTR->autoflush(1); P3_WTR->autoflush(1);

   if (my $pid = fork) {
      unless (close P1_WTR && close P2_WTR && close P3_WTR) {
         die "close failed in parent: !";
      }

      my @fhs = (*C1_RDR, *C2_RDR, *C3_RDR);

      my (%fhs_open, %output, %filenos);
      my $sin = '';
      for my $fh (@fhs) {
         vec($sin, fileno($fh), 1) = 1;
         $fhs_open{$fh} = $fh;
         $output{$fh}   = "";
         $filenos{$fh}  = fileno($fh); #used if filehandle unexpectedly closes on us.
      }

      #could this be an infinite loop without the execed program outputting/running forever?
      while (values %fhs_open) {
         #do I need to check for exceptions too?
         select(my $rout=$sin, undef, undef, undef);

         for my $fh (values %fhs_open) {
            if (!defined fileno($fh)) {  #could this happen?
               syswrite(STDERR, "filehandle unexpectedly closed" . " at " . __FILE__ . " line " . __LINE__ . ".\n");
               delete $fhs_open{$fh};
               vec($sin, $filenos{$fh}, 1) = 0;          
            }
            elsif (vec($rout, fileno($fh), 1)) { 
               my $retval = sysread($fh, $output{$fh}, $max_read_bytes, length($output{$fh}));
               if (!$retval) {
                  if (!defined $retval) {
                     syswrite(STDERR, "sysread returned an error: $!" . " at " . __FILE__ . " line " . __LINE__ . ".\n");
                  }
                  delete $fhs_open{$fh};
                  vec($sin, fileno($fh), 1) = 0;
                  close($fh) || die "Can't close filehandle \"$fh\": $!";
               }
            }
         }
      }

      wait();
      my $status = $?;

      # as long as eval/exec isn't fatal, $did_exec should be correct.
      my $did_exec = ($output{*C3_RDR} eq $JUST_BEFORE_EXEC);
      if (substr($output{*C3_RDR}, 0, length($JUST_BEFORE_EXEC)) eq $JUST_BEFORE_EXEC) {
         substr($output{*C3_RDR}, 0, length($JUST_BEFORE_EXEC)) = "";
      }

      return(map({\$_} @output{@fhs}), $did_exec, $status, $status >> 8);
   }
   else {
      die "cannot fork: $!" unless defined $pid;

      open(TERM_STDERR, ">&STDERR") || die "Can't dup STDERR: $!\n";
      $SIG{__WARN__} = sub { print TERM_STDERR @_; };
      $SIG{__DIE__}  = sub { print TERM_STDERR @_; print P3_WTR @_; };

      unless (close C1_RDR && close C2_RDR && close C3_RDR) {
         die "close failed in child: $!";
      }

      open(STDOUT, ">&P1_WTR") || die "Can't dup P1_WTR: $!\n";
      open(STDERR, ">&P2_WTR") || die "Can't dup P2_WTR: $!\n";

      print(P3_WTR $JUST_BEFORE_EXEC) || die "Can't write to parent: $!";
      #could exec be fatal?  could eval be fatal?
      eval { exec { $system_command } $system_command, @args; };

      print P3_WTR "Can't exec \"$system_command\": " . ($@ ? $@ : $!) . "\n";
      if (-d $system_command) {
         print P3_WTR "\"$system_command\" is a directory and can't be executed\n";
      }

      close P1_WTR; close P2_WTR; close P3_WTR; close TERM_STDERR;
      exit;
   }
}
__END__


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

Date: Sat, 17 Mar 2001 11:04:23 +1100
From: mgjv@tradingpost.com.au (Martien Verbruggen)
Subject: Re: Perl 4
Message-Id: <slrn9b5ag7.9vo.mgjv@martien.heliotrope.home>

[Didn't you see my request last time around? I'll repeat it here, please
read it:

Please, in the future, put your reply _after_ the suitably trimmed
text you reply to. It's the generally accepted convention on this
group, and Usenet in general.]


On Fri, 16 Mar 2001 09:10:46 +0100,
	Kiwitter@qns.de <kiwitter@qns.de> wrote:
> hi @ all...
> 
> it so that i develop. on my linux system and port. it to system V unix with
> perl 4.

Then I strongly, very strongly suggest that you install Perl 5 on that
other system.

Perl 4 is only a historical curiosity now, and for most people obviously
a rather uniteresting one at that, given the response to my suggestion
to put the diffs on CPAN, needed to compile perl 4 on Linux.

It should not be used in any serious way any more. That's why  asked
whether you were still running DOS 3.1 or SunOS 4.1. The only reasons I
know of machines still running those is for historical reasons, and
because of ancient legacy software or data that needs to be kept running
for legal (tax) reasons.

Perl4 is like that. No one in their sane mind develops against it
anymore.

[Jeopardectomy performed]

Martien
-- 
Martien Verbruggen              | 
Interactive Media Division      | Never hire a poor lawyer. Never buy
Commercial Dynamics Pty. Ltd.   | from a rich salesperson.
NSW, Australia                  | 


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

Date: Fri, 16 Mar 2001 21:38:39 GMT
From: "David Ehrens" <nospam@nospam.net>
Subject: Re: PERL and ASP
Message-Id: <zJvs6.12256$mH4.3060774@typhoon.ne.mediaone.net>

[some hasty individual just wrote in message xxxx...]
> ASP newsgroup and ask there.  Good luck.

You just got the bum's rush. I think this is definitely *.perl.misc
stuff and warrants a polite answer.

One mechanism for running Perl programs is as Perlscript. If you get
yourself the latest version of ActivePerl and install it, you can modify
your Perl program to run as Perlscript within an active server page,
much as you would with VBscript.

Good luck!
David Ehrens

***

Example of PerlScript reading data from a Oracle 8i database:

***[odbc.asp]***

<%@ LANGUAGE = PerlScript%>
<html>
<head>
<title>Perl reads data from a Oracle 8i database</title>
</head>

<body bgcolor=#ffffff>

<IMG SRC="logo.gif" ALT="logo">

<h3>Perl reads data from a Oracle 8i database</h3>
<hr>
<br>

<%
 $Conn = $Server->CreateObject("ADODB.Connection");
 $Conn->Open( "tiger","system","manager" );
 $sql = "select * from scott.perldata";
 $RS = $Conn->Execute($sql);
%>

<p><h3> Here are the results from the query:<br>
<i><%= $sql %></i></h3><p>

<table cellpadding=5 border=1 cellspacing=5>

<%
 while ( ! $RS->{EOF} ) {
  %>
  <tr>
  <td><%=$RS->Fields(0)->{Value}%></td>
  <td><%=$RS->Fields(1)->{Value}%></td>
  <td><%=$RS->Fields(2)->{Value}%></td>
  <td><%=$RS->Fields(3)->{Value}%></td>
  <td><%=$RS->Fields(4)->{Value}%></td>
  <td><%=$RS->Fields(5)->{Value}%></td>
  <td><%=$RS->Fields(6)->{Value}%></td>
  </tr>
  <%$RS->MoveNext;
  }
 $RS->close;
 $Conn->close;
%>

</table>
<br>
<hr>
<br>

<%
 $url = $Request->ServerVariables('PATH_INFO')->Item;
 $_ = $Request->ServerVariables('PATH_TRANSLATED')->Item;
 s/[\/\\](\w*\.asp\Z)//m;
 $params = 'filename='."$1".'&URL='."$url";
 $params =~ s#([^a-zA-Z0-9&_.:%/-\\]{1})#uc '%' . unpack('H2', $1)#eg;
%>

$url = <%=$url%><br>
$_ = <%=$_%><br>
$params = <%=$params%><br>

</body>
</html>





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

Date: 17 Mar 2001 01:23:49 GMT
From: "Scott R. Godin" <webmaster@webdragon.munge.net>
Subject: Re: Perl Version Question
Message-Id: <98ueb5$rrb$0@216.155.32.136>

In article <98p5aq$cqf$1@slb1.atl.mindspring.net>, "Ed Doyle" 
<doyleed@sprynet.com> wrote:

 | Suppose I add a perl script that has a line
 | 
 | use File::Basename;
 | 
 | Is there something I can put in that script that queries whether the 
 | version of perl being run at that site in fact supports use 
 | File::Baseline.
             ^^^^
did you mean File::Basename or File::Baseline? :) 

other than the original respondent's suggestion of an eval, you can also 
specify a particular version of a module thusly: 

    use File::Spec 0.82; 

which will die if the version of File::Spec on the system is not as 
recent as that version.

 | Failing that, is there some way I can find out manually what was the 
 | first version of perl to support use File::Baseline;.

if it isn't installed you can always 

    >%perl -MCPAN -e shell 
    cpan> install File::Baseline

which will update the local machine (providing you are root, or 
providing you have a local CPAN.pm install that knows where your local 
~/lib/perl5/ is :) 

 | If there was, I could add a line checking if the version of perl was 
 | greater then x where x was the first version to support use 
 | File::Baseline;

there's also the 

require 5.005; 

which will die if the version of perl required is higher than the 
installed version. This may be necessary in some cases where the script 
in question uses some new feature of Perl that's not part of earlier 
versions.

-- 
unmunge e-mail here:
#!perl -w
print map {chr(ord($_)-3)} split //, "zhepdvwhuCzhegudjrq1qhw"; 
# ( damn spammers. *shakes fist* take a hint. =:P )


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

Date: Fri, 16 Mar 2001 17:51:40 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Quick struct question in perl. example code inc
Message-Id: <slrn9b567s.9k1.tadmc@tadmc26.august.net>

Chile <abcd@ntlworld.com> wrote:

>Can someone tell me if its possible to repreoduce the below c code in perl?


Yes, but why should they bother if you cannot be bothered to check
the Perl FAQ before posting to the Perl newsgroup?


>struct File_Info
 ^^^^^^

The answer is already in a file on your hard disk. Type:

   perldoc -q struct

      "How can I make the Perl equivalent of a C structure/
       C++ class/hash or array of hashes or arrays?"


>i was trying something like this but could not get it working


Try something like in the FAQ instead.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


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

Date: Fri, 16 Mar 2001 17:42:52 -0800
From: "Godzilla!" <godzilla@stomp.stomp.tokyo>
Subject: Re: Subroutine in separate files
Message-Id: <3AB2C11C.5F2F19CA@stomp.stomp.tokyo>

Dave Stang wrote:
 
(snippage)

> I have a rather large perl script that I have broken
> into several subroutines.  For manageability, I would
> like to keep the subroutines in separate files.
 
> Is there a way to do this without re-making perl?

Lacking clear and concise parameters, a presumption
is made your "separate files" means independent scripts
and, no one answer will be correct due to your not
providing a brief outline of your subroutines. Another
presumption is made these subroutines are moderately
complex in nature.

There is a very efficient way to accomplish this. Use
of LWP simple is a very viable alternative. Using this
module is especially nice if your subroutines are not
needed at times. This allows a shorter more efficient
master script which calls remote scripts as needed.

Research and learn about this LWP module. You can use
it to run and return results from a remote script,
within your master script.

However there is a note of caution. If your subroutines
are called everytime your master script is run, you would
do better to leave those subroutines in your script, as is.
Regardless of what method you employ to call remote scripts,
subroutines in your case, there will be inherent time lag.

Godzilla!


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

Date: Sat, 17 Mar 2001 01:43:50 -0000
From: "Hamish Lawson" <hamish_lawson@btinternet.com>
Subject: ZPT, a next-generation template technology
Message-Id: <98ufbu$kkh$1@uranium.btinternet.com>

The Zope Presentation Templates project is underway at Digital Creations
to develop a next-generation template technology for Zope* that is
XHTML-compliant and which makes it easier for designers to work with.
However it is hoped to design it in such a way that as much as possible
is not specific to Zope, in the belief that the technology is more
widely useful and could be adopted by other languages and tools.
Developers from other communities may want to consider contributing to
the design of ZPT to help keep it language-independent, and to consider
implementing the approach in their programming language of choice.

First of all some background on what is meant by "next-generation".

In the beginning programmers wrote program code with embedded HTML. Then
technologies like eperl, ASP, PHP and JSP allowed us to reverse this and
to embed program code in the HTML. However a school of thought wanted to
have greater separation of presentation and logic, and so various
template mechanisms were devised that provided just enough
programmability to control presentation, but which moved the business
logic out elsewhere. One example of this approach is Freemarker:

   <h1>$customername</h1>
    <table border="1">
        <tr>
            <td>Date</td>
            <td>Amount</td>
        </tr>
        <list deposits as deposit>
            <tr>
                <td>${deposit.date}</td>
                <td>${deposit.amount}</td>
            </tr>
        </list>
    </table>

Instead of custom tags some other template mechanisms use special
markers to designate control structures, but in general most template
mechanisms share the property that their templates are not compliant
with XHTML (though the rendered output may be). As such it can be
awkward trying to use such template mechanisms with authoring tools that
only understand XHTML.

The approach that the ZPT project is pursuing is to attach the control-
flow, formatting and placeholder directives as *attributes* of standard
XHTML tags. The example above thus becomes something like:

    <h1 zpt:insert="customername">Bob Smith</h1>
    <table border="1">
        <tr>
            <td>Date</td>
            <td>Amount</td>
        </tr>
        <tr zpt:repeat="deposit deposits">
            <td zpt:insert="deposit/date">01/02/2001</td>
            <td zpt:insert="deposit/amount">23.40</td>
        </tr>
    </table>

Because this doesn't make use of special tags, but employs attributes
instead, it should pass unscathed through most decent authoring tools.
Moreover (borrowing an idea from Enhydra's XMLC template scheme) the ZPT
template scheme allows typical sample content to be used as a proxy for
the real data (which is substituted by the template engine), so making
it easier to work with in an authoring tool.

More information on the rationale of attribute languages can be found

    http://dev.zope.org/Wikis/DevSite/Projects/ZPT/AttributeLanguage

An overview of ZPT can be found at

    http://www.zope.org/Wikis/DevSite/Projects/ZPT/VisionStatement


Hamish Lawson

* Zope is a leading open-source web application server and content-
management framework, written in Python by Digital Creations.






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

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 V10 Issue 509
**************************************


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