[29729] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 973 Volume: 11

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 25 14:10:11 2007

Date: Thu, 25 Oct 2007 11:09:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)

Perl-Users Digest           Thu, 25 Oct 2007     Volume: 11 Number: 973

Today's topics:
    Re: configurable variables in own file? <tzz@lifelogs.com>
    Re: configurable variables in own file? <tzz@lifelogs.com>
    Re: configurable variables in own file? <bik.mido@tiscalinet.it>
    Re: configurable variables in own file? <tzz@lifelogs.com>
    Re: Crypt::TripleDES and public/private keys <SteveSpamTrap@yahoo.com>
    Re: From "The Camel Book", Ch. 16 (IPC) xhoster@gmail.com
        How to fetch output of some other script in the current  ritugoyal12@gmail.com
    Re: How to fetch output of some other script in the cur <jurgenex@hotmail.com>
    Re: How to fetch output of some other script in the cur <josef.moellers@fujitsu-siemens.com>
    Re: HTML::Template <tzz@lifelogs.com>
    Re: Implementation of file input operator <> <uri@stemsystems.com>
        PID of exec  hendedav@gmail.com
        PID of exec  hendedav@gmail.com
    Re: PID of exec <peter@makholm.net>
    Re: PID of exec  hendedav@gmail.com
    Re: sockets problem <nobull67@gmail.com>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Thu, 25 Oct 2007 05:29:43 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: configurable variables in own file?
Message-Id: <m2bqansd0o.fsf@lifelogs.com>

On Wed, 24 Oct 2007 13:19:54 +0200 Michele Dondi <bik.mido@tiscalinet.it> wrote: 

MD> I can't see what problem could you possibly incur with require(), or
MD> even do(). I don't see that you really need to import or export
MD> anything, but which problems anyway?

Importing code just because you need data is an unnecessary security and
maintenance risk.  To import data structures from an external
configuration file, the OP should use XML, YAML, a DB backend,
AppConfig, or any other mechanism specifically designed for that
purpose.  I find AppConfig best for readable configurations, and YAML
best for complex data structures.

As an added benefit, with most of these there will be one place (a
logical configuration root) where configuration data can be found, so
you don't have $path and $mode and $another_config_variable all over the
code.

require() and do() should be reserved for importing Perl code.

Ted


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

Date: Thu, 25 Oct 2007 05:35:52 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: configurable variables in own file?
Message-Id: <m27ilbscqf.fsf@lifelogs.com>

On Wed, 24 Oct 2007 03:29:32 -0000 ivowel@gmail.com wrote: 

i> optimally, I would like syntax like

i> package mypackage:
i> require Exporter;
i> our @ISA= qw(Exporter);
i> our @EXPORT = qw( v1 v2 v3 v4 );
i> include mypackageconfig;
i> our ($v2, $v3, $v4) = ("a", "b", "c");
i> ($v1=~ /whatisit/);
i> ## a lot more stuff, a lot more variables, etc.

i> and the file mypackageconfig would just contain

i> our $v1= "user-please-set";

With AppConfig:

V1 = user-please-set
# V2 is a hash
V2 key1 = value1
V2 key2 = value2
# V3 is a list
V3 = one
V3 = two
V3 = three

YAML and XML can do this as well.  YAML will handle multi-level hashes
and lists, while XML may be better depending on your environment.  Any
one of them is easily parseable by other languages as well--don't limit
your data to just Perl interpretation.

The method you described has security and maintenance risks, and is not
portable.

Ted


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

Date: Thu, 25 Oct 2007 15:55:59 +0200
From: Michele Dondi <bik.mido@tiscalinet.it>
Subject: Re: configurable variables in own file?
Message-Id: <r281i35ihrkeadlirk26gos41jfq4n3dol@4ax.com>

On Thu, 25 Oct 2007 05:29:43 -0500, Ted Zlatanov <tzz@lifelogs.com>
wrote:

>MD> I can't see what problem could you possibly incur with require(), or
>MD> even do(). I don't see that you really need to import or export
>MD> anything, but which problems anyway?
>
>Importing code just because you need data is an unnecessary security and
>maintenance risk.  To import data structures from an external
>configuration file, the OP should use XML, YAML, a DB backend,
>AppConfig, or any other mechanism specifically designed for that
>purpose.  I find AppConfig best for readable configurations, and YAML
>best for complex data structures.
>
>As an added benefit, with most of these there will be one place (a
>logical configuration root) where configuration data can be found, so
>you don't have $path and $mode and $another_config_variable all over the
>code.
>
>require() and do() should be reserved for importing Perl code.

Granted, but I was just answering his literal question.


Michele
-- 
{$_=pack'B8'x25,unpack'A8'x32,$a^=sub{pop^pop}->(map substr
(($a||=join'',map--$|x$_,(unpack'w',unpack'u','G^<R<Y]*YB='
 .'KYU;*EVH[.FHF2W+#"\Z*5TI/ER<Z`S(G.DZZ9OX0Z')=~/./g)x2,$_,
256),7,249);s/[^\w,]/ /g;$ \=/^J/?$/:"\r";print,redo}#JAPH,


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

Date: Thu, 25 Oct 2007 11:40:24 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: configurable variables in own file?
Message-Id: <m2prz3qhaf.fsf@lifelogs.com>

On Thu, 25 Oct 2007 15:55:59 +0200 Michele Dondi <bik.mido@tiscalinet.it> wrote: 

MD> On Thu, 25 Oct 2007 05:29:43 -0500, Ted Zlatanov <tzz@lifelogs.com>
MD> wrote:

MD> I can't see what problem could you possibly incur with require(), or
MD> even do(). I don't see that you really need to import or export
MD> anything, but which problems anyway?
>> 
>> Importing code just because you need data is an unnecessary security and
>> maintenance risk.  To import data structures from an external
>> configuration file, the OP should use XML, YAML, a DB backend,
>> AppConfig, or any other mechanism specifically designed for that
>> purpose.  I find AppConfig best for readable configurations, and YAML
>> best for complex data structures.
>> 
>> As an added benefit, with most of these there will be one place (a
>> logical configuration root) where configuration data can be found, so
>> you don't have $path and $mode and $another_config_variable all over the
>> code.
>> 
>> require() and do() should be reserved for importing Perl code.

MD> Granted, but I was just answering his literal question.

I think it's important to see beyong the literal question.  As with the
OP here, often the real need (separate configuration from code) was
hidden by the immediate need (how do I import Perl code).

Ted


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

Date: Thu, 25 Oct 2007 08:57:31 -0400
From: Steve <SteveSpamTrap@yahoo.com>
Subject: Re: Crypt::TripleDES and public/private keys
Message-Id: <5obi6tFm1i9fU1@mid.individual.net>

 ... but how does this relate back to Perl, through the 
"Crypt::TripleDES" module?  This module does not appear to take in a key 
as any of its input parameters... just the text to be 
encrypted/decrypted, and a passphrase.  Is what "Crypt::TripleDES" calls 
the "passphrase" actually the private key value that you're referring 
to?  I do appreciate all the background information, but is anyone out 
there actually using this "Crypt::TripleDES" module in Perl?


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

Date: 25 Oct 2007 16:35:59 GMT
From: xhoster@gmail.com
Subject: Re: From "The Camel Book", Ch. 16 (IPC)
Message-Id: <20071025123601.080$Gq@newsreader.com>

Ben Morrow <ben@morrow.me.uk> wrote:
> Quoth rihad <rihad@mail.ru>:
> > Chapter 16 "Interprocess Communication" of "Programming Perl" has this
> > part:
> >
> > use Fcntl ':flock';
> > eval {
> >     local $SIG{ALRM} = sub { die "alarm clock restart" };
> >     alarm 10;               # schedule alarm in 10 seconds
> >     eval {
> >         flock(FH, LOCK_EX)  # a blocking, exclusive lock
> >             or die "can't flock: $!";
> >     };
> >     alarm 0;                # cancel the alarm
> > };
> > alarm 0;               # race condition protection
> > die if $@ && $@ !~ /alarm clock restart/; # reraise
>
> It should be noted that this won't work under 5.8 with 'safe signals',
> as $SIG{ALRM} won't be called until after flock returns (which is
> exactly what you're trying to avoid).

On my system at least, the alarm causes flock to return immediately,
setting $! to "Interrupted system call", rather than automatically
restarting it.  That means that $SIG{ALRM} will be called almost
immediately.  Of course, it also means that on my system the whole thing
can be done much more easily, without any dies or evals.

Xho

-- 
-------------------- http://NewsReader.Com/ --------------------
The costs of publication of this article were defrayed in part by the
payment of page charges. This article must therefore be hereby marked
advertisement in accordance with 18 U.S.C. Section 1734 solely to indicate
this fact.


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

Date: Thu, 25 Oct 2007 05:18:14 -0700
From:  ritugoyal12@gmail.com
Subject: How to fetch output of some other script in the current running perl script?
Message-Id: <1193314694.744816.302990@v29g2000prd.googlegroups.com>

Hi,
I want to execute some script (May or May not be perl script) from a
perl script and print the output of that executed script.
My Operating system are Windows and Mac OS(Unix).
I was trying the following code without success:


Code
$Response = system("start test.wbt");
print $Response;

By the above code I am able to execute test.wbt but program doesnt
wait for test.wbt to get executed.

Please help me what i m doing wrong also it would be nice if somebody
could explain me why the above program fails and how can I print the
output of the executed programin the current program.

Thanks!!!!!



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

Date: Thu, 25 Oct 2007 14:40:35 GMT
From: "Jürgen Exner" <jurgenex@hotmail.com>
Subject: Re: How to fetch output of some other script in the current running perl script?
Message-Id: <DV1Ui.3870$hG2.3476@trndny05>

ritugoyal12@gmail.com wrote:
> I want to execute some script (May or May not be perl script) from a
> perl script and print the output of that executed script.
> $Response = system("start test.wbt");
> print $Response;
>
> By the above code I am able to execute test.wbt but program doesnt
> wait for test.wbt to get executed.

That can't be. system() will first execute whatever external command you 
pass as a parameter. Depending on what arguments you pass to system() it may 
or may not use the shell. For details please see the documentation for 
system().
And of course it will wait for the external command to terminate, too. 
However it has no control over other processes that are launched by the 
external command in turn.

> Please help me what i m doing wrong also it would be nice if somebody
> could explain me why the above program fails and how can I print the
> output of the executed programin the current program.

The documentation of system() explains the reason very explicitly, please 
see the third paragraph, first and third sentence.

It is also explained in FAQ
    "Why can't I get the output of a command with system()?"

jue




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

Date: Thu, 25 Oct 2007 14:28:32 +0200
From: Josef Moellers <josef.moellers@fujitsu-siemens.com>
Subject: Re: How to fetch output of some other script in the current running perl script?
Message-Id: <ffq25l$jbs$1@nntp.fujitsu-siemens.com>

ritugoyal12@gmail.com wrote:
> Hi,
> I want to execute some script (May or May not be perl script) from a
> perl script and print the output of that executed script.
> My Operating system are Windows and Mac OS(Unix).
> I was trying the following code without success:
>=20
>=20
> Code
> $Response =3D system("start test.wbt");
> print $Response;
>=20
> By the above code I am able to execute test.wbt but program doesnt
> wait for test.wbt to get executed.
>=20
> Please help me what i m doing wrong also it would be nice if somebody
> could explain me why the above program fails and how can I print the
> output of the executed programin the current program.

If you ask perldoc what "system" does, it would tell you that "The=20
return value is the exit status of the program as returned by the "wait" =

call."
The same paragraph would then tell you that "This is not what you want=20
to use to capture the output from a command, for that you should use=20
merely backticks or "qx//", as described in "`STRING`" in perlop.".

HTH,

Josef
--=20
These are my personal views and not those of Fujitsu Siemens Computers!
Josef M=F6llers (Pinguinpfleger bei FSC)
	If failure had no penalty success would not be a prize (T.  Pratchett)
Company Details: http://www.fujitsu-siemens.com/imprint.html



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

Date: Thu, 25 Oct 2007 05:38:35 -0500
From: Ted Zlatanov <tzz@lifelogs.com>
Subject: Re: HTML::Template
Message-Id: <m23avzsclw.fsf@lifelogs.com>

On Tue, 23 Oct 2007 21:50:31 -0700 Ankur <jainankur@gmail.com> wrote: 

A> I am new to perl. I am using HTML::Template module to display tmpl
A> files on the web server. But I need to use HTML::Template::Expr module
A> now as well, to display the values of certain expressions in the same
A> script.

A> How can I use both HTML::Template and HTML::Template::Expr module in
A> the same perl and template file.

My suggestion is to try the Template Toolkit (module "Template" on
CPAN).  You may like it better than HTML::Template; I do after many
years of using both.  It does everything HTML::Template can do AFAIK.

Ted


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

Date: Thu, 25 Oct 2007 17:28:53 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Implementation of file input operator <>
Message-Id: <x7bqanw1bh.fsf@mail.sysarch.com>

>>>>> "hg" == himanshu garg <himanshu.garg@gmail.com> writes:


  hg>      There was a race condition in which the child process died during
  hg> the second read call and the parent kept waiting. Using a signal
  hg> handler for SIGCHLD required many code changes. Using sysread, I no
  hg> longer see the error.

this sounds like you are reading from a pipe connected to the child. in
general i always say use sysread on pipes and sockets and bypass perlIO
or stdio. managing buffering can be more work but you gain total control
over things which is more important. using an event loop also makes it
much easier to manage i/o on sockets and pipes.

uri

-- 
Uri Guttman  ------  uri@stemsystems.com  -------- http://www.stemsystems.com
--Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
Search or Offer Perl Jobs  ----------------------------  http://jobs.perl.org


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

Date: Thu, 25 Oct 2007 10:18:53 -0700
From:  hendedav@gmail.com
Subject: PID of exec
Message-Id: <1193332733.379046.99750@o3g2000hsb.googlegroups.com>

Gang,

     I have looked all over google groups on how to find the pid of
the exec command when using the fork/exec.  I will admit that I am not
overly familiar with the workings (I understand the idea though) of
these two commands.  Here is what I am working with.  I have a perl
script (see below) that calls a shell script that simply counts to
thirty while pausing for one second (basically is a script that does
nothing for 30 seconds so I can see if the PID is correct).


#!/usr/bin/perl

if (defined (my $pid = fork)) {
        if ($pid)
{                                                                     #
this test runs if the fork was successful
           local $SIG{CHLD} =
"IGNORE";                                 # eliminates the zombies
           print "pid is $pid\n, parent pid is $$\n";
        } else {                                                # the
following line runs in the child
           exec("./test.sh &");
           print "child pid is: $$\n";
           exit();
        }
   } else {
        print "there was a problem executing the script\n";
   }



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

Date: Thu, 25 Oct 2007 10:24:31 -0700
From:  hendedav@gmail.com
Subject: PID of exec
Message-Id: <1193333071.042302.240350@57g2000hsv.googlegroups.com>

Gang,

     I have looked all over google groups on how to find the pid of
the exec command when using the fork/exec.  I will admit that I am not
overly familiar with the workings (I understand the idea though) of
these two commands.  Here is what I am working with.  I have a perl
script (see below) that calls a shell script that simply counts to
thirty while pausing for one second (basically is a script that does
nothing for 30 seconds so I can see if the PID is correct).  What I am
trying to accomplish is trying to find the pid of the binary/script
that is executed from the exec command.  If I run the script below,
this would be a sample of what I get:


debian:/tmp# ./test.pl
     pid is 6330, parent pid is 6329
debian:/tmp# ps a
  PID TTY      STAT   TIME COMMAND
 2545 tty1     Ss+    0:00 /sbin/getty 38400 tty1
 2546 tty2     Ss+    0:00 /sbin/getty 38400 tty2
 2547 tty3     Ss+    0:00 /sbin/getty 38400 tty3
 2548 tty4     Ss+    0:00 /sbin/getty 38400 tty4
 2551 tty5     Ss+    0:00 /sbin/getty 38400 tty5
 2552 tty6     Ss+    0:00 /sbin/getty 38400 tty6
 2569 pts/1    Ss     0:00 -bash
 2578 pts/1    S      0:00 bash
 3104 pts/0    Ss+    0:00 -bash
 6331 pts/1    S      0:00 /bin/sh ./test.sh
 6346 pts/1    S      0:00 sleep 1
 6347 pts/1    R+     0:00 ps a

As you can see neither of the pids is the one from the exec command.
I also tried using the open command (which returns the pid correctly),
but I can not background the process (using an & at the end of the
command).  I need to find the pid of the exec command within the
parent perl script so that I can track it.  Any help would greatly be
appreciated.

Thanks,
Dave

#!/usr/bin/perl

if (defined (my $pid = fork)) {
   if ($pid) {      # this test runs if the fork was successful
     # eliminates the zombies
      local $SIG{CHLD} = "IGNORE";
      print "pid is $pid\n, parent pid is $$\n";
   } else {        # the following line runs in the child
      exec("./test.sh &");
      print "child pid is: $$\n";
      exit();
   }
} else {
   print "there was a problem executing the script\n";
}



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

Date: Thu, 25 Oct 2007 17:33:12 +0000
From: Peter Makholm <peter@makholm.net>
Subject: Re: PID of exec
Message-Id: <87lk9rje07.fsf@hacking.dk>

hendedav@gmail.com writes:

> As you can see neither of the pids is the one from the exec command.

exec() does not spawn a new process and do therefore not generate a
new process id. The exec function does never return so you 'print
"child pid is $$\n' statement is never executed (why didn't you winder
about this?).

> #!/usr/bin/perl
>
> if (defined (my $pid = fork)) {
>    if ($pid) {      # this test runs if the fork was successful
>      # eliminates the zombies
>       local $SIG{CHLD} = "IGNORE";
>       print "pid is $pid\n, parent pid is $$\n";
>    } else {        # the following line runs in the child
>       exec("./test.sh &");
>       print "child pid is: $$\n";

Try to exchange the above two lines of code and se if you don't get an
pid for the child which matches what test.sh have.

>       exit();
>    }
> } else {
>    print "there was a problem executing the script\n";
> }

//Makholm


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

Date: Thu, 25 Oct 2007 10:54:55 -0700
From:  hendedav@gmail.com
Subject: Re: PID of exec
Message-Id: <1193334895.578892.38090@19g2000hsx.googlegroups.com>

On Oct 25, 1:33 pm, Peter Makholm <pe...@makholm.net> wrote:
> hende...@gmail.com writes:
> > As you can see neither of the pids is the one from the exec command.
>
> exec() does not spawn a new process and do therefore not generate a
> new process id. The exec function does never return so you 'print
> "child pid is $$\n' statement is never executed (why didn't you winder
> about this?).
>
> > #!/usr/bin/perl
>
> > if (defined (my $pid = fork)) {
> >    if ($pid) {      # this test runs if the fork was successful
> >      # eliminates the zombies
> >       local $SIG{CHLD} = "IGNORE";
> >       print "pid is $pid\n, parent pid is $$\n";
> >    } else {        # the following line runs in the child
> >       exec("./test.sh &");
> >       print "child pid is: $$\n";
>
> Try to exchange the above two lines of code and se if you don't get an
> pid for the child which matches what test.sh have.
>
> >       exit();
> >    }
> > } else {
> >    print "there was a problem executing the script\n";
> > }
>
> //Makholm

I switched the two lines of code as suggested, and I did get a print
out, but it contained the same PID as the "my $pid=fork" statment.
Here is the output:

debian:/tmp# ./test.pl
child pid is: 6498
        fork pid is 6498, parent pid is 6497
debian:/tmp# ps au
USER       PID %CPU %MEM   VSZ  RSS TTY      STAT START   TIME COMMAND
root      2545  0.0  0.2  1576  492 tty1     Ss+  Oct24   0:00 /sbin/
getty 38400 tty1
root      2546  0.0  0.2  1576  492 tty2     Ss+  Oct24   0:00 /sbin/
getty 38400 tty2
root      2547  0.0  0.2  1576  488 tty3     Ss+  Oct24   0:00 /sbin/
getty 38400 tty3
root      2548  0.0  0.2  1580  496 tty4     Ss+  Oct24   0:00 /sbin/
getty 38400 tty4
root      2551  0.0  0.2  1580  496 tty5     Ss+  Oct24   0:00 /sbin/
getty 38400 tty5
root      2552  0.0  0.2  1580  496 tty6     Ss+  Oct24   0:00 /sbin/
getty 38400 tty6
hendedav  2569  0.0  0.8  3552 1912 pts/1    Ss   Oct24   0:00 -bash
root      2578  0.0  0.7  3044 1656 pts/1    S    Oct24   0:00 bash
hendedav  3104  0.0  0.8  3560 1924 pts/0    Ss+  Oct24   0:00 -bash
root      6499  0.0  0.5  2704 1136 pts/1    S    13:45   0:00 /bin/
sh ./test.sh
root      6503  0.0  0.2  1876  460 pts/1    S    13:45   0:00 sleep 1
root      6504  0.0  0.3  2584  880 pts/1    R+   13:45   0:00 ps au

I am trying to get the 6499 pid from the list.  That is the actual pid
of the process that is being executed in the exec statment.  Maybe I
didn't say things right in the first post, sorry.  :)

Dave



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

Date: Thu, 25 Oct 2007 10:01:20 -0700
From:  Brian McCauley <nobull67@gmail.com>
Subject: Re: sockets problem
Message-Id: <1193331680.305593.37710@o3g2000hsb.googlegroups.com>

On Oct 22, 2:10 am, "stanciuthe...@gmail.com"
<stanciuthe...@gmail.com> wrote:
> Hi,
> my name is valentin and i'm trying to create a server using sockets,
> the problem is that  after i receive the data from the client i can't
> send a message back if i will not send to the other clients the
> message that the socket received, this problem i heaved also found in
> a php application that i'm trying to develope,
>
> if you need to see the source you can find it below:
>
> http://pastebin.com/m30faafe4

I've downloaded that and after uncommenting the call to broadcast it
seems to do what it appears to be intended to do. (Which is to print
"USERLIST>matap" to all terminals whenever anyone enters a line
starting with a recognised command verb).

> Thank you, for helping me out

You will have to give a better explanation of what your code is doing
and how this differs from your expectations.

You could also make it strict. This makes it much less difficult for
people who what to try to help you (including, of course, yourself).

Please see the posting guidelines.





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

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.  

NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice. 

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 V11 Issue 973
**************************************


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