[22728] in Perl-Users-Digest
Perl-Users Digest, Issue: 4949 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed May 7 00:05:45 2003
Date: Tue, 6 May 2003 21:05:07 -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 Tue, 6 May 2003 Volume: 10 Number: 4949
Today's topics:
@Array - making it null <sammie@greatergreen.com>
Re: @Array - making it null <sammie@greatergreen.com>
Re: @Array - making it null <uri@stemsystems.com>
Re: Can't Create Text Files, Config problem <REMOVEsdnCAPS@comcast.net>
Re: Can't Create Text Files, Config problem <REMOVEsdnCAPS@comcast.net>
Re: Design Opinions - Dealing with Constants <REMOVEsdnCAPS@comcast.net>
Re: Design Opinions - Dealing with Constants <REMOVEsdnCAPS@comcast.net>
Re: Design Opinions - Dealing with Constants <REMOVEsdnCAPS@comcast.net>
Re: foolproof requires <REMOVEsdnCAPS@comcast.net>
Re: Forcing an rvalue context on a scalar expression <uri@stemsystems.com>
Re: How to fork and PID - revisited <anthony@no_spam.movielink.net.au>
Re: Including files in Perl <REMOVEsdnCAPS@comcast.net>
Re: Install/setup Net::SSH::PERL <kalinabears@hdc.com.au>
Locking and updating files... <look@my.signature>
Re: Locking and updating files... <chris@cmb-enterprises.com>
Re: Open With? <taariqq@yahoo.com>
Re: Passing hash and string to subroutine <REMOVEsdnCAPS@comcast.net>
Re: regex and extracting permutations <w.koenig@acm.org>
Re: removing last char of string <REMOVEsdnCAPS@comcast.net>
What is this nntp.perl.org thing; seems nifty (David Combs)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 07 May 2003 01:31:24 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: @Array - making it null
Message-Id: <MlZta.759942$L1.215064@sccrnsc02>
This is really basic, I am sure. But, I am not quite sure how to search for
it, so maybe by explaining it I can get some help:
I have an @Array which is defined. I process the info. Now I want the @Array
to be null, so I may do the process all over again. What is the proper
syntax to make an @Array disappear?
Thanks,
Brad
------------------------------
Date: Wed, 07 May 2003 01:33:41 GMT
From: "Brad Walton" <sammie@greatergreen.com>
Subject: Re: @Array - making it null
Message-Id: <VnZta.761168$F1.97169@sccrnsc04>
nevermind... found it.
"Brad Walton" <sammie@greatergreen.com> wrote in message
news:MlZta.759942$L1.215064@sccrnsc02...
> This is really basic, I am sure. But, I am not quite sure how to search
for
> it, so maybe by explaining it I can get some help:
>
> I have an @Array which is defined. I process the info. Now I want the
@Array
> to be null, so I may do the process all over again. What is the proper
> syntax to make an @Array disappear?
>
> Thanks,
> Brad
>
>
------------------------------
Date: Wed, 07 May 2003 03:31:21 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: @Array - making it null
Message-Id: <x78ytjqvp2.fsf@mail.sysarch.com>
>>>>> "BW" == Brad Walton <sammie@greatergreen.com> writes:
<rearranged as he top posted himself>
>> I have an @Array which is defined. I process the info. Now I want the
BW> @Array
>> to be null, so I may do the process all over again. What is the proper
>> syntax to make an @Array disappear?
BW> nevermind... found it.
so why don't you post what you found? you may have actually found a bad
method and will have problems with it. did you solve it with undef? i am
guessing that because above you mentioned the term defined. if you did
that, then it you did not find the correct way which is to assign an
empty list to the array:
@array = () ;
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: Tue, 06 May 2003 21:40:53 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Can't Create Text Files, Config problem
Message-Id: <Xns9373E6AEF79E5sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
csdude@hotmail.com (Mike) wrote in
news:46cdc619.0305061110.13863d23@posting.google.com:
> #!/usr/bin/perl
> $name=Mike;
>
> open(OUTFILE, ">>test.txt") or die "Error opening test.txt. $!,
> stopped";
> print OUTFILE "$name\n";
> close(OUTFILE);
>
> print "Location: http://www.myurl.com\n\n";
> exit;
Don't use "die" in CGI scripts; that's the source of your 500 error.
The "Error opening...." message was put into your Apache log. If you
look there, you'll get a hint from $!.
Almost certainly the problem is that the user the web server runs as
(usually "nobody" or "apache") doesn't have permission to create
files in whatever directory the cgi program is located in. This is a
Good Thing. Don't change that, as someone else in this thread has
suggested. Go create a data directory somewhere else for the CGI
programs to create their data in; make THAT directory writeable by
the web server user.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uHIjY96i4h5M0egRApqdAKCF1veyrFZRv8gNEkxz3ldakGC/6ACg3l42
j4tjq8kDq56TLjDfhmMEufE=
=xW5/
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 06 May 2003 21:42:29 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Can't Create Text Files, Config problem
Message-Id: <Xns9373E6F442BD2sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
Matt Van Zilen <matt@nospam.liek.net> wrote in
news:DZTta.4268$zh4.983141499@newssvr10.news.prodigy.com:
> The user account that apache is running as cannot create files in
that
> directory. You could change the file permissions in the directory.
No he should NOT. CGI programs have no business creating and
changing files in the CGI program directory.
Please don't post Jeopardy-style (top-post).
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uHJ9Y96i4h5M0egRAlGSAJ0X7KE/poZ0dUZbFajC7lkGIHWkmgCg8N3L
867XPcbMfT6sPJHxZrmjD34=
=uTPA
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 06 May 2003 20:30:16 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Design Opinions - Dealing with Constants
Message-Id: <Xns9373DAB52B2B4sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
yf110@vtn1.victoria.tc.ca (Malcolm Dew-Jones) wrote in
news:3eb80613@news.victoria.tc.ca:
> In your globals file, environment.pl, include one more variable
that
> is the list of the global variable names, and then use that list
to
> declare which variables you use in the scripts.
>
> something like
>
> # environment.pl
> $useful_path = 'the/path';
> @some_things = ('One', 'Two' );
>
> @global_var_names = qw( $useful_path @some_things);
>
> now when ever you use your globals, do something like the
following
>
> # script.pl
>
> # BEGIN needed so the globals load before the "use..."
statements
> BEGIN{ require "environment.pl" }
> use strict;
> use vars @main::global_var_names;
>
> $useful_path # no error
> $usefull_path # typo detected
The problem with this approach is that if you need to use the
included constants in more than one module -- and you will, on any
reasonably-large project -- you run into trouble because perl won't
'require' the same file twice. So you either have to be darned sure
to require the file in the main package (and sometimes that's beyond
your control), or you have to add a "package main" statement to your
environment.pl file and prefix all its variable names with main::
everywhere in your program, or .... ah, but see my solution later in
this thread. (sorry about the teaser, but it seemed more appropriate
to post it as a response to the original poster).
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uGGUY96i4h5M0egRAvr7AJ9AAA+LJgRsStsjLIP7EGPnoqpGHgCgqUUc
seg+B0jHrYP6I4HIQtSjnsI=
=EWPr
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 06 May 2003 20:32:48 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Design Opinions - Dealing with Constants
Message-Id: <Xns9373DB22D9822sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"henq" <henq _ replace 0 by o <hvtijen@h0tmail.c0m>> wrote in
news:3eb8185a$0$45379$1b62eedf@news.wanadoo.nl:
> #usage:
>
> *config = \%::config;
> eval require "$myConfig.pm" or die $!;
>
> print $config{path_a};
The problem with a global hash is that it doesn't catch typos.
print $config{Path_A}; # ooops!
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uGIqY96i4h5M0egRApIqAJ9ilDaTHznVPp96aPQ9azPy5EbHbACg9eLE
SwYET5tUULe1ezcwyc5WLss=
=vZ7Y
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 06 May 2003 21:06:29 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Design Opinions - Dealing with Constants
Message-Id: <Xns9373E0D9FFD2Csdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"Kevin Vaughn" <kevin.vaughn@ttu.edu> wrote in
news:vbfemoj1e9hba1@corp.supernews.com:
> I've created a large number of scripts that reference a single
file
> containing all of my constants. I named the file environment.pl.
The
> file mainly contains paths. I include environment.pl using a
> "required" statement.
>
> Is this good or bad design? I'm particularly interested in the
> downsides.
The big downside is that require is "smart". It will not include the
same file twice (unless you hack around with %INC, and You Probably
Don't Want To Do That). This creates a problem if you try to use
environment.pl from two different packages. Sooner or later, you
will need to do this.
What happens is this:
# File Foo.pm
package Foo;
require 'environment.pl';
# Now there are lots of variables defined: $Foo::this,
$Foo::that.
# File Bar.pm
package Bar;
require 'environment.pl'; # Does NOT happen -- perl already did
it.
# Now you might THINK you have $Bar::this and $Bar::that, but
no.
One solution to that problem is to force all your constants to be in
package main.
# File environment.pl
package main;
$this = 'something'; $that = 'something else'; # etc
Now environment.pl only has to be require'd once. But all references
to the config variables have to have an explicit package:
# File Foo.pm
my $website = "http://$main::this/"; # for example
Or force them to be in package "environment". Same difference.
In my opinion, this is ugly and cumbersome. Your opinion may vary.
I find it much better to put the systemwide config variables into
their own module. Call it Environment.pm if you like. Use the
Exporter module to export symbols into the caller's namespace --
whatever module happens to need them. This also gives control to the
caller as to which variables to import. Let me explain with a
concrete example:
# File Environment.pm
use strict;
package Environment;
use Exporter;
use vars qw/@ISA @EXPORT_OK/;
@ISA = qw/Exporter/;
# Now, for each constant you want to define, do this:
use vars '$this'; # MUST be single quotes (or q// or qw//)
$this = 'something'; # whatever the value should be
push @EXPORT_OK, '$this'; # single quotes again
use vars '$that';
$that = 'something else';
push @EXPORT_OK, '$that';
# Main program, myprog.pl
use strict;
use Environment qw($this); # choose which variable to include
print "main: $this\n";
# File Foo.pm
use strict;
use Environment qw($this $that);
print "Foo: $this $that\n";
Clear so far?
No doubt you've already spotted the problem with this approach: Using
Environment.pm is now easy, but writing Environment.pm now becomes a
royal pain in the ass. Ugh, who wants to write three lines of code
to initialize each variable?
You can eliminate one line by getting rid of 'use vars' and being
explicit about the package name:
# Environment.pm again
$Environment::this = 'something';
push @EXPORT_OK, '$this';
But that's still annoying. It's a lot of code duplication, and a lot
of opportunity for errors.
My solution is to use subroutines to eliminate this code duplication.
Here it is:
# File Environment.pm
package Environment;
use Exporter;
@ISA = 'Exporter';
no strict; # see text below!
sub set_scalar {
my $vn = shift; # variable name (no leading $)
$$vn = shift; # Store value
push @EXPORT_OK, '$'.$vn; # Export its name
}
sub set_array {
my $vn = shift;
@$vn = @_;
push @EXPORT_OK, '@'.$vn;
}
sub set_hash {
my $vn = shift;
%$vn = @_;
push @EXPORT_OK, '%'.$vn;
}
# The above will be the same for any Environment.pm you ever
write.
# The code below is specific to your particular app:
set_scalar this => 'something';
set_scalar that => 'something else';
set_array some_array => qw/an array of things/;
set_hash some_hash => (one=>'ONE', two=>'TWO');
You use this Environment.pm as described earlier. Each module or
program that needs one or more variables will specify them on the
'use' line:
# main program
use strict;
use Environment qw($this @some_array);
Now. Why "no strict"? This is one of the rare instances where "use
strict" works against you. In order to avoid mindless repetition of
variable names, I chose to use symbolic references. Symrefs are
*usually* a bad design choice. But not always.
A word of caution: "no strict" is like driving without a seat belt,
so be careful :-) But it's only for one small module, so the risk is
tolerable.
If you want your Environment.pm variables to be truly constant (and
you probably do), this can be accomplished with one small tweak:
use Readonly; # doesn't come with perl; available on CPAN
sub set_scalar {
my $vn = shift; # variable name (no leading $)
Reaconly::Scalar $$vn => shift; # Store value
push @EXPORT_OK, '$'.$vn; # Export its name
}
sub set_array {
my $vn = shift;
Readonly::Array @$vn => @_;
push @EXPORT_OK, '@'.$vn;
}
sub set_hash {
my $vn = shift;
Readonly::Hash %$vn => @_;
push @EXPORT_OK, '%'.$vn;
}
Now your modules can't accidentally (or purposely) modify $this or
$that or any other variables you declare in Environment.pm
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uGoMY96i4h5M0egRAjPVAKDrhDV3Mk8uu2hN4Xq21FY/ke5PRACeLSQV
9gQFRPfhj3V2C2J2ZdKHk64=
=4giu
-----END PGP SIGNATURE-----
------------------------------
Date: Tue, 06 May 2003 21:51:51 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: foolproof requires
Message-Id: <Xns9373E88ADF5E9sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
info@analysisandsolutions.com (Analysis&Solutions) wrote in
news:b993pf$e7a$1@reader1.panix.com:
> Hi Folks:
>
> I've got a module on my website for public consumption which
validates
> credit card numbers. I'm reworking it so error messages are
> internationalized. The internationalization is performed by
creating
> separate language files. Each of those files set common variables
but
> with their respective languages. I then require that language file
> depending on the $Language parameter given to the method.
>
> The trick is to make sure the appropriate path is used to get the
> language file, regardless of the current working directory and
> operating system. Below are summarizations of the key parts of
the
> files to demonstrate my approach. Is this approach foolproof? Is
> there a more elegant way to do it?
>
> vvvvvvvvvv ./ccvs.pm (in part) vvvvvvvvvvvvvvvvv
>
> package CreditCardValidationSolution;
>
> use File::Spec::Functions;
> use File::Basename;
> use File::stat;
>
> sub validateCreditCard(\$;\$\@\$\$\$) {
That's one ugly-ass prototype. You sure you know what you're doing?
Anyhow.
Your approach sounds overly complex. Why not create auxiliary
modules that would act as wrappers, one for each language? That way,
if someone needed to use two or more languages, they could specify it
in their program, rather than having to install two or more copies of
your module on their site.
Something like: (warning, untested. Just a blue-sky brainstorm)
# Caller's program:
use CreditCardValidationSolution::EN;
....
# CreditCardValidationSolution/EN.pm
use CreditCardValidationSolution;
$err01 = "You are a dolt.";
$err02 = "Invalid checksum": # whatever
# CreditCardValidationSolution/FR.pm
use CreditCardValidationSolution;
$err01 = "Vous etes un idiot."
$err02 = "...." # whatever
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uHS0Y96i4h5M0egRAh8wAJ9HQWrJGBRIo1pqVQ0Xbej4zoWRegCg7GCm
bz/qVvFnp/58yRtARxVgPC4=
=+HQg
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 07 May 2003 02:55:32 GMT
From: Uri Guttman <uri@stemsystems.com>
Subject: Re: Forcing an rvalue context on a scalar expression
Message-Id: <x7el3bqxcs.fsf@mail.sysarch.com>
>>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
AS> Uri Guttman <uri@stemsystems.com> wrote in comp.lang.perl.misc:
>> >>>>> "AS" == Anno Siegel <anno4000@lublin.zrz.tu-berlin.de> writes:
>>
AS> Abigail <abigail@abigail.nl> wrote in comp.lang.perl.misc:
>> >>
>> >> Consider this:
>> >>
>> >> sub foo {$_ [0] = 1}
>> >> my @q;
>> >> foo $q [2];
>> >> print scalar @q;
>> >>
>> >> This prints 3 because you created $q [2]. But suppose you had called
>> >> 'foo $q [-1]', how large should @q be afterwards? Which element was
>> >> created?
>>
AS> All true, but the error shouldn't happen just because foo( $q[ -1]) is
AS> called, only when foo() actually tries to assign to its argument.
>>
>> but a sub call creates an alias to that element which doesn't exist. it
>> can be undef since there is no slot to create alias to.
AS> ...but $q[ 12] doesn't exist either, but is legal in places where $q[ -1]
AS> isn't. The difference would be that (with an empty array) $q[ -1] can
AS> never be allocated.
AS> I don't understand the second sentence.
i said the same thing but in a different way. $q[12] can be allocated
since it can count from the 0 slot. $q[-1] can't be located nor
allocated since it must count from the end and the array is empty. -1
would then mean the 'real' -1 slot which can't be accessed.
simple math here. the negative numbers are based on the array size. if
the array has 1 element, a -1 index refers to the 0 slot (1 - 1). so if
the array is empty it refers to the (0 - 1) -1 slot which cannot exist.
AS> Hmm... referencing and aliasing seems to be the key. "1 for $q[ -1]"
AS> also triggers it. Still, the behavior is unexpected, considering that
AS> read-access is usually possible with any array and any index, even
AS> large negatives. Also, how can a prepended "scalar", or a "do{}"
AS> wrapped around heal it? Something is flaky here and needs attention.
dunno how they 'fix' it. i still don't consider it a bug as my math
above shows. an empty array doesn't have a -1 slot.
AS> Ah, c'mon, 0 is a respectable end too. Emptiness has nothing to do
AS> with it, the same happens with a non-empty array for large negative
AS> indices, once they point past (err, before) the beginning of the array.
it is the size and not the end index that is used in the negative index
calculation. look at the above.
AS> I still think there's a bug involved, but the solution may be less
AS> straight-forward than I was hoping for.
i think the scalar and do{} fixes may be bugs. :)
i haven't looked into their behavior and i may later.
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: Wed, 07 May 2003 11:16:51 +1000
From: "Tony" <anthony@no_spam.movielink.net.au>
Subject: Re: How to fork and PID - revisited
Message-Id: <pan.2003.05.07.01.16.44.55980@no_spam.movielink.net.au>
On Tue, 06 May 2003 15:09:49 +0000, ctcga wrote:
> "Tony" <anthony@no_spam.movielink.net.au> wrote:
>>
>> START: open (FILE, $file) or die "Could not open: $file\n";
>> foreach my $schedule(<FILE>)
>> {
>> my $local_time_day = day_time(); # code not shown for this
>> my $time_day = (extracted from $file); # code not shown for this
>> my $data = (extracted from $file); # code not shown for this
[...]
>> I tried the following:
>>
>> if ("$local_time_day eq $time_day") # Compare for a match...
>> {
>> if (fork() == 0)
>> {
>> my $child_pid = $$; # Get child PID
>> close SCHEDULE; # Close previously opened file handle
>> process_data($data); # Send data to be processesed by sub
>> exit; # Exit child if processing completed
>> }
>> }
>> }
>
> Your lexical variable $child_pid is useless. It isn't used inside of it's
> scope, and it doesn't exist outside of it's scope. Also, it's not
Well, you are unfortunately (For me) right - the aim is
to capture the PID of the fork process (The child) and store it
for later use.
I have found one way, define
my $process_data_pid = 0;
at the beginning and then setting $process_data_pid in the fork'ed
part of the program (Seems to work fine).
> You're closing a filehandle named SCHEDULE, but you show opening one called
> FILE.
Outch...It should have been FILE, was trying to ensure it was closed
in the child process (Not needed there).
>> That does work (Start a new process) but various docs talk about signals,
>> kids, $$ for PID etc. which has confused me.
>>
>> The "process_file" program is something like:
>>
>> sub process_file
>> {
>> ...
>> my $external = "/some/path/program";
>> my $file = $_[1];
>> my $params = "abc";
>> system "$external $params $file";
>> }
>>
>> It would seem that the external file processor should
>> be started something like:
>>
>> sub process_file
>> {
>> ...
>> if (fork() == 0)
>> {
>> $pocess_file_pid = $$; # Get players PID before EXEC
>> exec "$external $params $file"; or die "Could not exec $!\n";
>> }
>> }
>
> Why do you want two different forks in the same program? If you're
> having problems with fork, try to get away with as few forks as possible.
If only that was possible...
The first fork is needed to separate the "process_data" from the
main loop scanning the FILE for DAY/TIME matches.
>> I see a small problem here - this snippet will return as soon as
> Uh, if you want to process stuff serially, process it serially.
I need both...:-)
The first fork seperates a process (Child) to continue processing
data passed from the main loop when a DAY/TIME match is found.
The second fork is to start the external program and get the PID
from it. The first child process, "process_data", should then check
the stored PID to see if it is running before trying to send the
next file to the external program. This is kind of a replacement
for the "system()" call which would normally continue after the
external program is finished. I know that "system()" is much
easier to use as it returns as soon as the external program
has completed but how would I be able to kill the external
program ? Without knowing the PID it is hard, killing
the perl child does not "kill" the external program (I have
tried).
I there was no need to be able to kill the program when the main
loop wants to send a new list of files, it would be easy.
But this is needed...
>> I somehow need to have the "process_data"
>> sub check for the process running and when it is finished, send
>> the next file.
>
> Why are you explicitly forking in the first place then?
>
> There is already an excellent way to start a process and then
> wait until it's done--the system command.
See above...
>> Could i use "waitpid" for that by checking the $process_pid ?
>
> No. Because you don't seem to have a variable $process_pid. Or at
>> What is the right way to store the pid's and where? I have defined
>
> The only (good) way for the parent to know the child's pid is to capture it
> from the fork command itself: my $child_pid=fork;
> Once you are in the child, the child can use $$ to get the child pid, but
> can't easily pass that up to the parent.
> If the child needs the parent's pid, the parent should: my $parent_pid=$$;
> before the fork, and the child can read it from $parent_pid.
>
>> I want to be able to store the $process_file_pid and $child_pid somewhere
>> so that I can kill both processes if a new event is trigered by my
>> main loop at the beginning. This will enable me to run a new
>> set of files.
>
> There is no natural way for a process to get it's grandchild's pid.
> You could use IPC from the child to the parent to report the grandchild's
> I don't know to where you are trying to go.
I have explained it a bit more - hope it is clearer, thanks
Tony
--
--------------------------------------------------------------
To reply directly send to: anthony AT movielink DOT net DOT au
Replace AT and DOT with @ and . and mail will get through.
Any spammers will be persued until they get booted off the net
------------------------------
Date: Tue, 06 May 2003 21:08:50 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Including files in Perl
Message-Id: <Xns9373E13FDA997sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
PropART <temp1_NO_SPAM_@williamc.com> wrote in
news:3EB79F63.A20F1BA6@williamc.com:
> So, if I'm understanding everything that's being said in this
thread
> correctly, the situation is this:
>
> if I want to put a bunch of scalar variable in an include file AND
use
> strict in the including files, I'll need to declare the variables
with
> our in the including file. Which also implies that if I change the
> include file I'll need to change the declaration in all of the
> including files.
>
> However, your suggestion of putting the values into a hash could
work
> around the problem at the expense of a little extra code to get
the
> value out of the hash. Thanks for the help.
For an alternate solution, see my post of today's date in response to
"Design Opinions - Dealing with Constants", in this newsgroup.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uGqfY96i4h5M0egRAnh/AJ4iwostA/dl5852lQTvYFwlGSNGuACgkKuF
+b/p9upf9l5Z/JPEjOaYi8k=
=8IlE
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 7 May 2003 11:44:04 +1000
From: "Sisyphus" <kalinabears@hdc.com.au>
Subject: Re: Install/setup Net::SSH::PERL
Message-Id: <3eb865ed$0$1420@echo-01.iinet.net.au>
"Anand Ramamurthy" <anand_ramamurthy@yahoo.com> wrote in message
news:761041e6.0305061050.17cd5e54@posting.google.com...
> I am trying to install Net::SSH::PERL in Windows 2000 & Windows XP.
> Net::Telnet is working fine for me.
>
Quackie's advice is probably the way to go. (You might need to append '.ppd'
to the 'ppm install...' line he provided.)
The Win32 version supports only one of the SSH protocols (SSH2 iirc).
Support of SSH1 is on the author's todo list, but has not yet been done
afaik.
And there's no Net::SSH::W32Perl available for perl 5.8.
So, if you need SSH1 support (or are running perl 5.8), you're currently on
your own. To that end, I can however provide Math::GMP binaries for Win32
(both perl 5.8 and perl 5.6). You can find them at:
http://robgil.hypermart.net/w32perl/math_gmp.html
The 'soulcage' site has a ppm of Math::Pari for 5.6, and I can provide one
for perl 5.8 (if needed). There's a bug or 2 in Math::Pari on 5.8 - but
hopefully they wouldn't affect you.
Btw, you can build GMP on Win32 using the Mingw32 compiler, and running in
an 'MSYS' shell. The resultant 'libgmp_3.dll' works fine with any Windows
compiler.
Cheers,
Rob
------------------------------
Date: 07 May 2003 02:53:35 GMT
From: David Scarlett <look@my.signature>
Subject: Locking and updating files...
Message-Id: <Xns9374836EF2317dscarlett@210.49.20.254>
I want to delete certain lines from a file, but I'm not sure how to do
it while keeping the file locked....
One way I could think of was to write the file to another file,
skipping the unwanted lines, and then delete the original and rename
the 2nd file to that of the original, however I can't see any way of
stopping the original from being read while it's being deleted...
Or, I could make a copy of the original file, open the copy for
reading, open the original for writing, get an exclusive lock on the
original, and read from the copy into the original, skipping the
unwanted lines and then truncate the original and delete the copy...
What's the best way to go about this?
Thanks.
--
David Scarlett
dscarlett@_ _ _ _ _ _ _ _
_ _ _ _ _ optusnet.com.au
------------------------------
Date: Tue, 06 May 2003 23:23:13 -0400
From: Chris Dutton <chris@cmb-enterprises.com>
Subject: Re: Locking and updating files...
Message-Id: <chris-B62539.23231206052003@corp.supernews.com>
In article <Xns9374836EF2317dscarlett@210.49.20.254>,
David Scarlett <look@my.signature> wrote:
> I want to delete certain lines from a file, but I'm not sure how to do
> it while keeping the file locked....
>
> One way I could think of was to write the file to another file,
> skipping the unwanted lines, and then delete the original and rename
> the 2nd file to that of the original, however I can't see any way of
> stopping the original from being read while it's being deleted...
>
> Or, I could make a copy of the original file, open the copy for
> reading, open the original for writing, get an exclusive lock on the
> original, and read from the copy into the original, skipping the
> unwanted lines and then truncate the original and delete the copy...
>
> What's the best way to go about this?
>
> Thanks.
Or you could open the file for both reading and writing. If memory
serves, it's something like:
open(FH, "+<some_file.txt");
------------------------------
Date: Tue, 6 May 2003 21:13:01 -0400
From: "Tariq" <taariqq@yahoo.com>
Subject: Re: Open With?
Message-Id: <b99mg2029d8@enews3.newsguy.com>
"Eric Schwartz" <emschwar@pobox.com> wrote in message
news:etod6ivy5k7.fsf@wormtongue.emschwar...
> > Reason behind all of this is that I am trying to learn some buzz-word
> > technologies that I hear are somehow related to the field of
> > Bioinformatics.
>
> I understand the impulse-- believe me, I do. It's nice to have a
> fully buzzword-compliant resume. But you have to look past the
> buzzwords to what you want to do with them, or else you have no focus
> when you're learning them.
That is part of the puzzle I am trying to solve / understand ... what the
field of BioInfo is, and what technology to learn. Trying to do that before
enrolling into a graduate program. I guess instead of trying to do too much,
I will start learning one thing at a time ... maybe Perl, right after PL/SQL
> > Database programming is one,
>
> There's a reason they have graduate-level courses in this. Database
> programming is easy; database design is very hard. I can't remember
> offhand who it was (Dijkstra? Knuth?), but someone very seminal in
> computer science said, "Show me your data structures, and I'll show
> you your code". This is doubly (trebly?) true for databases.
I got some clarification of that in one of the oracle groups! There is a
reason why ther is a shortage of DBAs ...
> > Knowledge of Unix/Linux is another,
>
> Your best solution here is to download a copy of your favourite Linux
> distribution of choice, and break a lot of things. You'll learn more
> by fixing your mistakes than any other way, IME.
Just finished installing Red Hat 6.2, and am downloading RH 9.0 ... should
be fun.
> > and Perl
>
> Of all the things you mentioned, this is the only one relevant to this
> group. There is a book on Bioinformatics with Perl, put out by
> O'Reilly, but I can't recall more. You can google for reviews.
> You'll also want "Learning Perl", and "Programming Perl", also
> published by O'Reilly. In addition, a healthy supply of patience and
> willingness to look things up and try stuff out instead of just
> getting 'stuck' will go a long way.
Sorry to have bombarded all with irrevelant information. I felt a little
stupid asking a very basic question, and just wanted to throw some
perspective in, and was trying to get someone involved in the discussion :-)
> > and different XML derivatives
>
> Perl does XML quite well.
Very glad to hear that ... maybe it is PHP that I will leave alone.
Different dialects of XML are used heavily in Biological fields, to handle
Protein and other databases.
> > are talked about as the necessary tools. Since
> > PHP is famous for server side scripting with MySQL, I thought if I could
> > eliminate CGI from the mix, that would be one less technology to learn
:-)
>
> You'd better ask that in a PHP newgroup, then. I do know there is a
> standalone PHP interpreter you can use to write scripts in, but why
> you'd want to do that when you have Perl, shell, Ruby-- anything else,
> really-- I can't imagine. I'm currently teaching myself PHP, just so
> I can put it on my list of "Languages I Know", but I find it
> frustrating and difficult to get anything useful done in it.
Hmmm ... interesting. I was just presuming that PHP was the best thing to be
used with MySQL ... looking at all those .php extensions on the web ... did
not know all that could be done with Perl!
> Also, don't top-post; it's rude, and gets your messages read by
> significantly fewer people. Intersperse your comments with the
> message you're replying to, like I'm doing, and quote the minimum
> required to preserve context.
I agree, will keep that in mind. Thanks Eric.
> -=Eric
> --
> Come to think of it, there are already a million monkeys on a million
> typewriters, and Usenet is NOTHING like Shakespeare.
> -- Blair Houghton.
------------------------------
Date: Tue, 06 May 2003 21:32:06 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: Passing hash and string to subroutine
Message-Id: <Xns9373E531F70E0sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
"James E Keenan" <jkeen@concentric.net> wrote in
news:b99ejs$s2g@dispatch.concentric.net:
> "Rich Pasco" <richp1234@hotmail.com> wrote in message
> news:3EB7BEFE.8020605@hotmail.com...
>> James E Keenan wrote:
>>
>> > sub process_events {
>> > my($criteria, $body) = @_;
>> > my %crit = %$criteria;
>> > print "a=$crit{'a'}\n";
>> > print "b=$crit{'b'}\n";
>> > print "\nbody = $body\n";
>> > }
>>
>> That would not only make it easier to see, it would also incur
the
>> runtime cost of copying all the data over to a local variable.
Of
>> course, that same cost was paid in my initial implementation
which
>> started this thread.
>>
> True. There are tradeoffs. The benefit of the clarity is obvious.
> But the real run-time cost in speed can only be determined by
> benchmarking it against the real data you're going to use in your
> production script.
I personally find the "$$foo{bar}" notation extremely difficult to
read. My eyes start reading it, see "$$foo", my brain thinks "scalar
dereference", then I come skidding to a halt when I see the "{".
I greatly prefer the "$foo->{bar}" notation. It reads nicely from
left to right. "$foo points to a hash; look up the 'bar' key".
I do not think that "$foo{bar}" is any "clearer" than "$foo->{bar}",
once you get used to using references, as all intermediate Perl
programmers should. I feel that copying the referenced hash data to
a local hash is wasteful and useless.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uHAPY96i4h5M0egRAmO2AKCLA9fJXIx7hkXUuiL3Ujv3KOMG+wCfSFTC
V/MkefeE+mfmQCiFykuUoao=
=tcoy
-----END PGP SIGNATURE-----
------------------------------
Date: Wed, 07 May 2003 03:45:23 +0200
From: Winfried Koenig <w.koenig@acm.org>
Subject: Re: regex and extracting permutations
Message-Id: <3EB86533.8090904@acm.org>
Ryan McCarthy wrote:
> I am tryng to use regular exprssions to extract permutations of a
> sequence into an array. Here are the parameters that I need to meet.
>
> The sequence is in the form
>
> ACK
> SG[IL]N
> SG[IUD]
> [NO]S[YR]NR
> etc...
>
> where the needed function would produce teh array with the following
> entries
>
> ACK
> SGIN
> SGLN
> SGI
> SGU
> SGD
> NSYNR
> NSRNR
> OSYNR
> OSRNR
>
> Additional things to consider:
> - there is no limit on the number of lines that can be entered
> - there is no limit on the number of letters that can be between the
> brackets [ ]
> - there is no limit on the number of bracketed characters per line
my last attempt:
#!/usr/local/bin/perl
use strict;
use warnings;
my @sequence = qw( ACK SG[IL]N SG[IUD] [NO]S[YR]NR ?[AB]* A[][*?{}]B );
my @array = enum(@sequence);
foreach (@array) { print "$_\n" }
sub enum {
map { m/\[(.+?)\]/ ? enum(map "$`$_$'", split //, $1) : $_ } @_;
}
__END__
Winfried Koenig
------------------------------
Date: Tue, 06 May 2003 21:35:33 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: removing last char of string
Message-Id: <Xns9373E5C7C3090sdn.comcast@216.166.71.239>
-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1
John Strauss <john.thetenant-s@moving-picture.com> wrote in
news:20030506190101.023b0b3b.john.thetenant-s@moving-picture.com:
> On Tue, 6 May 2003 10:52:18 -0700
> "Chris" <chris_12003@yahoo.com> wrote:
>>
>> Is there a way in perl to remove the last character of a string?
>> i.e. if $var = "New York," I would want just "New York" without the
>> extra comma.
>
> $var =~ s/.$//;
Won't work if the last character is a newline.
- --
Eric
print scalar reverse sort qw p ekca lre reh
ts uJ p, $/.r, map $_.$", qw e p h tona e;
-----BEGIN xxx SIGNATURE-----
Version: GnuPG v1.2.1 (MingW32) - WinPT 0.5.13
iD8DBQE+uHDRY96i4h5M0egRAh3oAJ9klNel1wD8Yyt51o973T2AuOuy8gCeOHbC
9xSn6jBZVsnvkDfCxyNT814=
=PZj3
-----END PGP SIGNATURE-----
------------------------------
Date: 6 May 2003 23:01:35 -0400
From: dkcombs@panix.com (David Combs)
Subject: What is this nntp.perl.org thing; seems nifty
Message-Id: <b99suf$fj9$1@panix1.panix.com>
I saw nntp.perl.org mentioned in an article here,
so went over to it.
The page there has a title-like heading "newsgroups";
rather, it looks like a bunch of email lists.
Questions:
. what is this nntp.<some-word>.org? Are there others
besides perl's?
. How does it work? The choosing of a list to read,
and it's then "reading the list", displaying the
chosen messages, etc?
. Is it a perl program? Or is this elist-reading
system some generic capability on the internet,
written in eg c, c++, python, etc -- ie, not
necessarily perl?
. I just happenee to see it mentioned in an article,
this nntp.perl.org. Where would one look to discover
that it exists? In some existing perl documentation?
. Anything else to say about it?
. It would be nice if, like google groups, you could
a whole series of articles "printed out together" into
one file, to be looked at off-line. or cut and pasted
at one's leisure, etc.
(Well, in google groups, you can get an entire
thread output into one file; of course, that's
for newsgroups -- but from what I saw in the
nntp.perl.org site, those lists too have threads.)
. how long has this nntp.perl.org been around for?
Thanks,
David
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 4949
***************************************