[19015] in Perl-Users-Digest
Perl-Users Digest, Issue: 1210 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Jun 28 14:05:52 2001
Date: Thu, 28 Jun 2001 11:05:18 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <993751518-v10-i1210@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Thu, 28 Jun 2001 Volume: 10 Number: 1210
Today's topics:
Basic Questions about Locking a DBM <amittai@amittai.com>
Re: cant modify $_[x] ???? <tinamue@zedat.fu-berlin.de>
Re: cant modify $_[x] ???? <patelnavin@icenet.net>
Re: Checking for duplicates before appending to file <davsoming@lineone.net>
Re: Checking for duplicates before appending to file <mbudash@sonic.net>
Client/Server question <gortona@cs.man.ac.uk>
Re: Compile perl on Solaris (Andy Dougherty)
cpan shell: remove or uninstall command <R.Zimmermann@uke.uni-hamburg.de>
create html files <mr.thanquol@gmx.de>
Re: Graphical user interfacing? <gortona@cs.man.ac.uk>
Re: Help: How to make a hash global <Jenda@Krynicky.cz>
Re: Help: How to make a hash global <ren@tivoli.com>
Re: Highlight message in DOS (remove the obvious)
how can i get the output of a forked child? (Thomas Schulze-Velmede)
Re: lvalue functions nobull@mail.com
Need help again with global vars! (^CooL^)
Re: Need help again with global vars! (Anno Siegel)
Re: Need help again with global vars! nobull@mail.com
Re: Need help again with global vars! <ren@tivoli.com>
Re: New knowledgebase site - looking for authors, artic <info@kbaseonline.com>
Re: Newbie question: What's the opposite of chop? <mjcarman@home.com>
Re: Newbie question: What's the opposite of chop? <rwellum@irp-view5.cisco.com>
Re: Newbie question: What's the opposite of chop? <rwellum@irp-view5.cisco.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 27 Jun 2001 12:02:48 +0200
From: "Amittai Aviram" <amittai@amittai.com>
Subject: Basic Questions about Locking a DBM
Message-Id: <9hcivr$8bb$1@rznews2.rrze.uni-erlangen.de>
Quite new to Perl, I ask for patience at the outset.
I have just finished writing a series of CGI scripts that involve receiving
data from forms, saving the data in DBM files (main files and
cross-referencing indexes), make the data available in a variety of views,
and enable the user to edit the data or delete the records. (The user also
gets e-mail notification when the forms come in.) As a beginner, however,
I've written the whole thing using dbmopen and dbmclose without any special
module for a particular sort of DBM -- following the _Introduction to
Perl -- and I did not put any locking mechanism into any of the files. This
is obviously a bad thing, so I've been researching how best to lock the DBMs
during sessions. Here is where I am totally baffled.
The "Camel Book" begins a (rather _brief_) discussion on this matter with
this:
"If you have a DBM file that doesn't provide its own explicit locking
mechanism, ..." How do I know whether it does or not? Later, the authors
mention Gnu GDBM as the one kind that locks _implicitly_ -- but that's
obviously not "explicit." Furthermore, I have been writing the scripts
using ActivePerl in Windows and then implementing them after testing (and
with necessary changes, debugging, and trouble-shooting) on Unix (FreeBSD,
Apache 2 server). ActivePerl does not seem to have the GDBM module.
The "camel book" gives an example of how to use a semaphore file to lock
your DBM -- using the tie() rather than the old dbmopen() function. (I've
noticed on perl.com that you are not supposed to use dbmopen() anymore --
saw this after I had written all my scripts. No problem.) Can the
semaphore be an empty file that merely has a filename?
So -- in sum -- two questions:
1. Is GDBM the best way to deal with this problem, and, if so, what does
the "camel book" mean by "explicit" and "implicit" -- i.e., can you simply
use GDBM and not worry about having to call flock at all?
2. Can a semaphore file be empty?
Thanks!
Amittai Aviram
------------------------------
Date: 28 Jun 2001 14:18:49 GMT
From: Tina Mueller <tinamue@zedat.fu-berlin.de>
Subject: Re: cant modify $_[x] ????
Message-Id: <9hfec9$di511$3@fu-berlin.de>
hi,
Aman Patel <patelnavin@icenet.net> wrote:
> And I have 1 more question:
> why is e.g.
> &doRemovePipes( my $modifyable_copy_of_text = $text );
> why can $text be modifiable to begin with, What I mean to ask is what makes
> a variable modifyable/non-modifyable... apparently the following are
> read-only (i want to know why, perhaps a manpage would help but which man
> page!)
> $text = \'read-only text';
> &pass_to_function( 'read-only text?' );
well, variables are always modifiable, or if a variable is a
reference, then it is the same as the thing it is referencing.
that's what "variable" means.
e.g.
$text = "text"; # $text is modifiable, of course, because it
#contains a copy of "text"
mysub($test); # $text is modifiable here
$text = \$text2; # $text is modifiable only if $text2 is
$text = \3; # $text is *not* modifiable, because
3 is data and no variable, so if you
would try to change 3, you would try to change the
number 3.
mysub("constant"); # here you are feeding data, no variable
# to the sub. if you alter $_[0] in the sub, you
# would try to change the data itself, which is again not possible.
does that help?
--
http://tinita.de \ enter__| |__the___ _ _ ___
tina's moviedatabase \ / _` / _ \/ _ \ '_(_-< of
search & add comments \ \ _,_\ __/\ __/_| /__/ perception
please don't email unless offtopic or followup is set. thanx
------------------------------
Date: Thu, 28 Jun 2001 21:45:54 +0530
From: "Aman Patel" <patelnavin@icenet.net>
Subject: Re: cant modify $_[x] ????
Message-Id: <9hfl71$dp0te$1@ID-93885.news.dfncis.de>
"Tina Mueller" <tinamue@zedat.fu-berlin.de> wrote in message
news:9hfec9$di511
> does that help?
wow, thanks tina,
------------------------------
Date: Thu, 28 Jun 2001 18:07:39 +0100
From: "David Soming" <davsoming@lineone.net>
Subject: Re: Checking for duplicates before appending to file
Message-Id: <tjmoo2nkv3no69@corp.supernews.co.uk>
<snip>
> > open( EMAILS, ">>", "address.txt" )
> Umm, minor mistake of mine, that should be "<+" not ">>".
Ah! thats why :-) I thought you were showing an obscure method of using
append in this instance for checking dups. I was originally wanting to open
the file and create it, if it
didn't already exist, hence ">>" but yes, <+ operator is OK- I'll just
upload a blank file.
>
> > My server reports misconfiguration- even with chmod set at 755 or 777?
> > seems like "," ", " and/or the line:
>
> You are confusing which strings are quoted. There's a handle, then a
> comma, then a quoted string containing the mode to open the file in,
> then a quoted string containing the name of the file. I do not have a
> quoted comma, as you seem to be implying.
Yes confused! -my middle name :-)
>
> > die "Could not open address.txt in rw mode: $!";
> > reports server misconfig too?
>
> The purpose of having an error message with die is to allow you to find
> out what went wrong. The httpd reports a server misconfig if the CGI
> script exits in an unusual manner. To see why, either put in a line
> use CGI qw(fatalsToBrowser);
> or else post a snippet of the log produced.
I do not have access to remote server logs. I use CGI qw(fatalsToBrowser);
anyway but only got default (standard)server message returned suggesting
software error or misconfig. Now I know it was software error that caused
it, by commenting out code line by line.
>
> Anyway, I would assume that the die line is causing the script to exit,
> but it the reason it is being reached is that the open is failing.
> Probably because "address.txt" is a relative pathname, and *you* are
> assuming that the cwd is the same as where the perl/cgi script is, but
> in probable fact, the cwd is something else.
>
> > (no further error details or access to logs)
>
> Why not? You don't want us to help you?
AH! where would I be without your help? <grovel>
> > > while( <EMAILS> ) {
> > > next unless /^\Q$email{address}\E$/i;
> > > print <<"\t\tHEREDOC"
> > > The email address you entered, <B>$email{address}</B>
> > > is already in our mailing list.
> > > HEREDOC
> > > exit;
> > > }
> > The above reports Software error:
> > Can't find string terminator "\t\tThe email address you entered,
> > <B>$email{address}</B>is already in our mailing list." anywhere before
> > EOF What exactly does that mean? have I implimented this right...
>
> There are two problems, both of which are very important. First off, I
> left off a semicolon after "\t\tHEREDOC" Second, have foolishly
> stripped out the tabs from my post.
>
k
>
> And you have an unmatched { from the while.
>
k
> Well, since you seem to be incapable of seeing tabs, I'll write the code
> with the tabs changed to spaces.
>
> while( <EMAILS> ) {
> next unless /^\Q$email{address}\E$/i;
> print <<" HEREDOC"; # I forgot the ; last time :)
> The email address you entered, <B>$email{address}</B>
> is already in our mailing list.
> HEREDOC
> exit;
> }
>
> When perl sees the symbol << it begins parsing a here-document. It
> pulls in the next string, then searches for that string surrounded by
> newlines (no extra whitespace allowed). By having the first instance of
> HEREDOC preceded by 16 spaces, it searches for \n, 16 spaces, HEREDOC,
> then \n. Then everything up to (but not including) the first \n becomes
> the passed string. Umm, could somebody give a clearer explanation of
> how here documents work?
>
Thanks, I never heard of here documents before! Ill be sure to read up on
them.
> > IM having to debug remotely too because flock() is not implemented on
> > my platform, although I could comment out- but still get the above
> > errors which doesn't further narrow things down much.
>
> Well, you could add a modifiyer to the flock line...
> replace:
> flock EMAILS, LOCK_EX
> or die "Could not gain flock for address.txt: $!\n";
> with:
> flock EMAILS, LOCK_EX
> or die "Could not gain flock for address.txt: $!\n"
> unless $^O =~ /OS with no flock/;
>
> Then you'll have a script which should run ok on both, assuming
> everything else works.
>
That's great!
Thanks very much for your time, and er..trouble ;-)
Cheers.
--
David Soming
'Just a head-banger- doing what I do best'
______________
------------------------------
Date: Thu, 28 Jun 2001 10:42:25 -0700
From: Michael Budash <mbudash@sonic.net>
Subject: Re: Checking for duplicates before appending to file
Message-Id: <mbudash-5F3D91.10422528062001@news.pacbell.net>
In article <tjf03trfgcem72@corp.supernews.co.uk>, "David Soming"
<davsoming@lineone.net> wrote:
> <snipped>
> > #------------------------------------------------------------
> > my $emails = 'address.txt';
> > open (EMAILS, ">>$emails") or die ("Can't open $emails: $!");
> > flock (EMAILS, 2);
> > seek (EMAILS, 0, 0); # rewind
> >
> > my $found = 0;
> > while (<EMAILS>) {
> > chomp;
> > if (/^$email{'address'}$/i) {
> > $found++;
> > last;
> > }
> > }
> >
> > if ($found) {
> > my $errormessage = "The address you entered, <B>$email{'address'}</B>
> > is already in our mailing list";
> > } else {
> > seek (EMAILS, 0, 2); # fast forward to eof
> > print EMAILS "$email\n";
> > }
> >
> > close (EMAILS); # flock (EMAILS, 8) not needed or advised!
> > #------------------------------------------------------------
> >
> Michael, I replaced my code with yours (exactly) and it still allows for
> duplicates?
hmmm... really? have you run it thru the debugger step-by-step?
of course, all the flock-ing in the world won't matter, and the file
could still be corrupted, unless *all* scripts modifying the file use
similar flock-ing...
> Would it have anything to do with scalar "my $emails" as my variable is
> globally predefined elsewhere as: "$email"?
huh?
> Thanks too for the flock 8 advisory!
no prob
--
Michael Budash ~~~~~~~~~~ mbudash@sonic.net
------------------------------
Date: Thu, 28 Jun 2001 17:56:59 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: Client/Server question
Message-Id: <3B3B61DB.1BDAE931@cs.man.ac.uk>
Hi everyone,
I am using IO::Socket to establish a client/server to monitor system
resources on hosts and report the results to a Tk interface.
The problem I am having is sending a list of commands and arguments to
the server from the client and then getting the results back.
On the client side I have the code to establish the connection and then
request commands from the server:
print $sock "USER:$parameter";
print scalar <$sock>;
print $sock "CPU";
print scalar <$sock>;
...
And on the server side I have:
while ($new_sock = $sock->accept()) {
$new_sock->autoflush(1);
while (defined($buf = <$new_sock>)){
@para = split(/:/, $buf);
if ($para[0] eq "USER"){
print
($new_sock&Details::details($para[1]);#package
}
elsif ($para[0] eq "CPU"){
print
($new_sock &Cpu::CPU_details);
}
...
}
}
But it just hangs. I have only been learning PERL for a few weeks so
any help will be much appreciated.
Sorry for the long question. Cheers
------------------------------
Date: Thu, 28 Jun 2001 14:36:53 -0000
From: doughera@maxwell.phys.lafayette.edu (Andy Dougherty)
Subject: Re: Compile perl on Solaris
Message-Id: <slrn9jmgan.614.doughera@maxwell.phys.lafayette.edu>
In article <ABw_6.43$y76.14795@typhoon.mn.mediaone.net>, Daniel Berger wrote:
>"Sourisseau" <pascal.sourisseau@businessobjects.com> wrote in message
>news:c9434ed2.0106270928.73fd8c96@posting.google.com...
>> Hi,
>> We would compile perl on Solaris 2.6 but...........
>> we try to understand where there is an error... but we don't.
>> If somebody has an idea or can help you,
>>
>>
>> Perl Distribution : 5.6.1
>> Solaris 2.6 with already an perl 5.6
>> cc : Forte 6 Update 1
>
>Your best bet is to give up on the Forte cc compiler. I have yet to have
>that compiler 'make' anything successfully. Try using gcc and see what
>happens.
I'm pretty sure others have had no trouble with the Forte compiler,
but I didn't see the original report here, so I don't have any
specific advice. In general, if it doesn't work, follow the advice in
INSTALL for reporting problems.
--
Andy Dougherty doughera@lafayette.edu
Dept. of Physics
Lafayette College, Easton PA 18042
------------------------------
Date: Thu, 28 Jun 2001 18:47:16 +0200
From: "Dr. Zimmermann" <R.Zimmermann@uke.uni-hamburg.de>
Subject: cpan shell: remove or uninstall command
Message-Id: <3B3B5F94.1880AE3C@uke.uni-hamburg.de>
Hi,
is there a remove or uninstall command in the cpan shell ?
OR how can I remove unwanted software from my perl installation
Roger
--
Dr. Roger Zimmermann *** Institute of Physiology, Hamburg
Martinistra/3e 52 D-20246 Hamburg Tel.: /40 42803 5351
-------------------------------- Fax.: /40 42803 4920
R.Zimmermann=at=Uke.Uni-Hamburg.de // roz=at=snafu.de
PGP-ID: Roger Zimmermann
KeyPrint=83 16 D1 82 06 71 16 60 6F 61 95 65 BB CA 02 E0
------------------------------
Date: Thu, 28 Jun 2001 16:25:34 +0200
From: "felix" <mr.thanquol@gmx.de>
Subject: create html files
Message-Id: <9hfemu$qlv$1@crusher.de.colt.net>
hi,
I'm also new to perl, but I'm really interested to use it and try to change
my shell-scripts to perl-scripts.
My first target is to create a script which produces a html file out of a
log file. The file is given via commandline as parameter
and has always the same format like this:
\[`date +%d.%m.%y\ %H:%M:%S`\] \[info\] `basename $0` : $LOG_FILE_CONTENT
( for example "[ 28.06.01 16:19:20 ] [info] posting-2-newsgroup:
~~content~~~" )
I've got a shell script which uses that logfile and creates a html-file out
of it by adding the tags to the lines
( and by the way it checks for [error] & [critical] & [warn] and changes the
color of that lines by adding tables to the
html file)
it's just simple input -> check -> output -work .... is it hard to build
something in perl or does somebody has something
like a perl-two-liner which does that job?
thx
felix
------------------------------
Date: Thu, 28 Jun 2001 18:19:28 +0100
From: Andrew Paul Gorton <gortona@cs.man.ac.uk>
Subject: Re: Graphical user interfacing?
Message-Id: <3B3B6720.12D6CA23@cs.man.ac.uk>
flash wrote:
>
> Is it possible to interface with a grapical program (GUI)?
> What modules?
>
> This would be on windows.
>
> thanks,
>
> --
> #--*--*--*--*--*--*--*--*--*--*--#
> # The smash script archive. #
> # http://www.floodbox.com #
> #--*--*--*--*--*--*--*--*--*--*--#
Perl/Tk is very easy to learn and the demos included with the module are
a good guide. Also O'Reilly has a good book called "Learning Perl/Tk
------------------------------
Date: Thu, 28 Jun 2001 14:22:34 GMT
From: Jenda Krynicky <Jenda@Krynicky.cz>
Subject: Re: Help: How to make a hash global
Message-Id: <1103_993738154@JENDA>
On 27 Jun 2001 08:54:04 -0700, viscido@u.washington.edu wrote:
>
> I am working with a tied hash, call it %db, using the MLDBM module. At
> the top of the script I'm running, I tie %db through MLDBM to
> data.db. Now, I want to call a subroutine in a module I made, and have
> that subroutine perform some operations on %db. So for instance,
> perhaps I have a printsort.pm module, which contains the printsort()
> subroutine... and printsort()'s job is to take all the items in %db,
> sort by key, and then print out the key and value of those items in
> sorted order, using a special format that's designed just for
> printsort().
Assuming you have a statement
package printsort;
in the packagesort.pm add this
*db = \%main::db;
somwehere into the module.
After executing this statement $printsort::db is exaclty the same thing as $main::db
And remember that %db cannot be "our".
You have to use
use vars qw(%db);
instead of
our %db;
!
HTH, Jenda
------------------------------
Date: 28 Jun 2001 11:47:32 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Help: How to make a hash global
Message-Id: <m366dgv9ej.fsf@dhcp9-173.support.tivoli.com>
On Thu, 28 Jun 2001, Jenda@Krynicky.cz wrote:
> On 27 Jun 2001 08:54:04 -0700, viscido@u.washington.edu wrote:
>>
>> I am working with a tied hash, call it %db, using the MLDBM
>> module. At the top of the script I'm running, I tie %db through
>> MLDBM to data.db. Now, I want to call a subroutine in a module I
>> made, and have that subroutine perform some operations on %db. So
>> for instance, perhaps I have a printsort.pm module, which contains
>> the printsort() subroutine... and printsort()'s job is to take all
>> the items in %db, sort by key, and then print out the key and value
>> of those items in sorted order, using a special format that's
>> designed just for printsort().
>
> Assuming you have a statement
> package printsort;
> in the packagesort.pm add this
> *db = \%main::db;
> somwehere into the module.
>
> After executing this statement $printsort::db is exaclty the same
> thing as $main::db
>
> And remember that %db cannot be "our".
What makes you think that?
> You have to use
>
> use vars qw(%db);
> instead of
> our %db;
> !
I don't think that is true. From perlfunc(1):
... The `our'
declaration has no semantic effect unless "use
strict vars" is in effect, in which case it lets
you use the declared global variable without
qualifying it with a package name. ...
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 28 Jun 2001 16:51:42 GMT
From: "--Rick" <no_trick@my-de(remove the obvious)ja.com>
Subject: Re: Highlight message in DOS
Message-Id: <ygJ_6.13463$C81.1063923@bgtnsc04-news.ops.worldnet.att.net>
"Anthony" <hoa@nortelnetworks.com> wrote in message
news:9hddag$5t$1@bcarh8ab.ca.nortel.com...
| Hi all,
|
| My perl script run on WinNT which prints out messages to DOS prompt
when
| errors were occurred. I want to highlight some keywords in the
messages. If
| anyone knows what are the special characters to turn on/off highlight
or
| change color in DOS prompt?
|
| Thanks.
|
In the bad old days of DOS, text attributes could be set using ansi
escape sequences. I haven't tried that in any of the modern dos
windows, so I don't know if it is still active. You could probably
pursue it with some searches for ansi.sys.
Another way to highlight that precedes ansi controls is to use text
decorations. Messages are typically have *** or something prepended to
them to get attention. This is very simple, but can be effective if it
isn't over-used.
-- Rick
------------------------------
Date: 28 Jun 2001 10:50:09 -0700
From: tsv.werbung@web.de (Thomas Schulze-Velmede)
Subject: how can i get the output of a forked child?
Message-Id: <227269e2.0106280950.523dd47b@posting.google.com>
Hi,
I tries the following code-snippet:
----------------------------
#!/bin/perl
#
# A full parallel cat...
open (LIST, "<$ARGV[0]") or die "Can't open file";
while(<LIST>){
if($pid = fork){
# parent here
next;
} elsif (defined $pid){
# child here
print;
exit;
} else {
die "Can't fork, father stopped";
}
}
close LIST;
----------------------------
and it worked fine.
I now want the father to collect the output of the childs. (In reality
the forked childs are shellscripts which will get executed by
Net::Telnet->cmd() on many different hosts, preferable in parallel.)
By now, the childs create a file /tmp/tmp$$ and the father wait()s for
all his childs to die. I would like to avoid using these files...
I would really appreciate anybodys help.
Thanks in advance
Best regards
Thomas
------------------------------
Date: 28 Jun 2001 18:04:15 +0100
From: nobull@mail.com
Subject: Re: lvalue functions
Message-Id: <u97kxwzfnd.fsf@wcl-l.bham.ac.uk>
Benjamin Goldberg <goldbb2@earthlink.net> writes:
> Currently, perl has the :lvalue attribute to allow you to assign to a
> subroutine call:
>
> somescope: {
> my $private;
> sub func : lvalue { $private }
> }
>
> func = 4;
>
> How difficult would it be to change perl to use a ruby-like syntax for
> this?
>
> somescope: {
> my $private;
> sub func { $private }
> sub func= { $private = shift }
> }
>
> func = 4;
>
> IMHO, seperate fetch and store methods make more sense than one single
> function which has to stand in for both.
How about the following syntax?
somescope: {
my $private;
use LvalueSubWithSeperateFetchAndStoreMethods func => {
FETCH => sub { $private },
STORE => sub { $private = shift },
};
}
__END__
# LvalueSubWithSeperateFetchAndStoreMethods.pm
package LvalueSubWithSeperateFetchAndStoreMethods;
use strict;
use warnings;
sub import {
# Should really consider version number
my $class = shift;
my $pkg = caller;
while (@_) {
my $func = shift;
my $methods = shift;
# Should really carp() if there's something wrong
$func = "${pkg}::$func" unless $func =~ /::/;
my $sub = sub : lvalue {
tie my $tied, $class, {
methods => $methods,
args=> [ \ (@_) ],
};
$tied;
};
no strict 'refs';
*$func = $sub;
}
}
sub TIESCALAR { bless $_[1], $_[0] };
sub FETCH { $_[0]{methods}{FETCH}->( map { $$_ } @{$_[0]{args}} ) };
sub STORE { $_[0]{methods}{STORE}->( $_[1], map { $$_ } @{$_[0]{args}} ) };
1;
__END__
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Jun 2001 08:51:26 -0700
From: cool133@hotmail.com (^CooL^)
Subject: Need help again with global vars!
Message-Id: <211c8e3f.0106280751.40b9b200@posting.google.com>
Hi all!
I am using mod_perl on Apache and I need to share certain variables
between packages and scripts (mostly configuration variables). More
precisely, I need to run an initial script - say init.pl - to
initialise configuration variables, then in subsequent scripts make
use of these variables or even modify them.
The problem is that when Apache gets a request, it may or may not
create a child process, and subsequent requests are not guaranteed to
be served by the same child process. Therefore all requests handled by
a child process that does not happen to be the same child process that
ran the initial script would find the variables undefined.
I know I could run Apache in single-process mode (httpd -X) but this
is terribly inefficient. I could also write the initial variables to a
file and have all subsequent scripts read from/write to the file. But
again, doing that in every script will slow things down.
Any suggestions?
Thanks beforehand for your support, and to Anno and Philip who have
helped me before.
Regards,
Clyde.
------------------------------
Date: 28 Jun 2001 16:31:20 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Need help again with global vars!
Message-Id: <9hfm4o$et1$2@mamenchi.zrz.TU-Berlin.DE>
According to ^CooL^ <cool133@hotmail.com>:
> Hi all!
>
> I am using mod_perl on Apache and I need to share certain variables
> between packages and scripts (mostly configuration variables). More
> precisely, I need to run an initial script - say init.pl - to
> initialise configuration variables, then in subsequent scripts make
> use of these variables or even modify them.
>
> The problem is that when Apache gets a request, it may or may not
> create a child process, and subsequent requests are not guaranteed to
> be served by the same child process. Therefore all requests handled by
> a child process that does not happen to be the same child process that
> ran the initial script would find the variables undefined.
I don't know about any mod_perl peculiarities (which may well be
relevant), but normally you'd just "use" the configuration module
at the beginning of the script. If it has been read before by
the same Perl process, it won't actually be read again.
> I know I could run Apache in single-process mode (httpd -X) but this
> is terribly inefficient. I could also write the initial variables to a
> file and have all subsequent scripts read from/write to the file. But
> again, doing that in every script will slow things down.
Hmm... if you want to read *and* write a file, that's quite a
different business. You'll have to lock the file appropriately
in a CGI environment.
Anno
------------------------------
Date: 28 Jun 2001 17:44:50 +0100
From: nobull@mail.com
Subject: Re: Need help again with global vars!
Message-Id: <u9ae2szh8d.fsf@wcl-l.bham.ac.uk>
cool133@hotmail.com (^CooL^) writes:
> I am using mod_perl on Apache and I need to share certain variables
> between packages and scripts (mostly configuration variables). More
> precisely, I need to run an initial script - say init.pl - to
> initialise configuration variables, then in subsequent scripts make
> use of these variables
Look into the PerlRequire directive.
> or even modify them.
Sorry no can do (at least not by simple means).
> I know I could run Apache in single-process mode (httpd -X) but this
> is terribly inefficient. I could also write the initial variables to a
> file and have all subsequent scripts read from/write to the file. But
> again, doing that in every script will slow things down.
There are modules on CPAN to tie variables to shared memory, which may
or may not be faster than having them in a file.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: 28 Jun 2001 11:32:20 -0500
From: Ren Maddox <ren@tivoli.com>
Subject: Re: Need help again with global vars!
Message-Id: <m3ae2sva3v.fsf@dhcp9-173.support.tivoli.com>
On 28 Jun 2001, cool133@hotmail.com wrote:
> Hi all!
>
> I am using mod_perl on Apache and I need to share certain variables
> between packages and scripts (mostly configuration variables). More
> precisely, I need to run an initial script - say init.pl - to
> initialise configuration variables, then in subsequent scripts make
> use of these variables or even modify them.
>
> The problem is that when Apache gets a request, it may or may not
> create a child process, and subsequent requests are not guaranteed
> to be served by the same child process. Therefore all requests
> handled by a child process that does not happen to be the same child
> process that ran the initial script would find the variables
> undefined.
>
> I know I could run Apache in single-process mode (httpd -X) but this
> is terribly inefficient. I could also write the initial variables to
> a file and have all subsequent scripts read from/write to the
> file. But again, doing that in every script will slow things down.
>
> Any suggestions?
You probably need to have a routine in each script that checks to see
if things are initialized and calls the initialization routine if the
are not.
--
Ren Maddox
ren@tivoli.com
------------------------------
Date: Thu, 28 Jun 2001 09:58:55 -0700
From: KBaseonline.com <info@kbaseonline.com>
Subject: Re: New knowledgebase site - looking for authors, articles or tips about Perl
Message-Id: <f1omjt09hkcg84ct95t453ln6oo448lvgj@4ax.com>
Hello Tony,
Thank you for your reply. I have been working on the site for the
last couple of days so I haven't had a chance to reply to the
different responses that have been generated by the posting I have
left.
I assure I do not have any funding whatsoever and I have undertaken
the entire project with out of pocket costs. I am not looking for
fame and glory but rather a place where people can go to read about
the industry and current technology. I have been in the IT industry
for the last 10 years and have been in the trenches with some of the
best developers around but I can only wirte so many article, tips or
tutorials are few categories when I am trying to have a place where
you go can that is vast with information. So that is why I have been
posting messages to try and obtain some content.
Again, I am not spamming the newsgroups and if it seems that way I am
truly sorry. I am just trying to get some content to share with other
people that wish to visit the site.
Again thank you very much for your reply. All comments and responses
are appreciated,
Thank you,
James
On Wed, 27 Jun 2001 23:15:04 GMT, tony@svanstrom.com (Tony L.
Svanstrom) wrote:
>Philip Newton <pne-news-20010627@newton.digitalspace.net> wrote:
>
>> On Wed, 27 Jun 2001 04:50:50 -0700, KBaseonline.com
>> <info@kbaseonline.com> wrote:
>>
>> > We are looking for articles, tips or tutorials on the Perl programming
>> > language.
>>
>> Good luck competing against all the other sites trying to offer similar
>> services. (And if it's free, I wonder how long you'll stay up, what with
>> the ad revenues tanking in the past couple of years.)
>
>Not only the past couple of years, but the past couple of months have
>made it far worse.
>
>This guy showed up in an XML-related NG with almost the same posting,
>but he never staid to reply to what people said; so on a "how serious is
>this guy"-scale I'd rate him as yet another "fame and lots of money
>without actually having to do it myself":er.
>
>
> /Tony
------------------------------
Date: Thu, 28 Jun 2001 09:07:04 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: Newbie question: What's the opposite of chop?
Message-Id: <3B3B3A08.AEB56F24@home.com>
Richard Wellum wrote:
>
> I used chop after reading a file to an array, to remove the
> "\n"'s, so I can process the array:
>
> foreach $all (@raw_data)
> {
> chop($all);
> .......more code;
> }
chomp() is the safer cousin to chop(), as it only removes the last
character *if* it matches $/ (normally "\n"). chop() always removes the
last character. Either will take a list argument:
chomp(@raw_data);
foreach (@raw_data) {
# do something...
}
> Now I have finished my manipulation of the array, and want to
> write this array back to the file. How to I add "\n"'s back to
> the end of each line in my array?
@raw_data = map{"$_\n"} @raw_data;
Although one would normally just add it while printing:
foreach (@raw_data) {
print "$_\n";
}
-mjc
------------------------------
Date: 28 Jun 2001 10:32:56 -0700
From: Richard Wellum <rwellum@irp-view5.cisco.com>
Subject: Re: Newbie question: What's the opposite of chop?
Message-Id: <y5auofr8jyrb.fsf@irp-view5.cisco.com>
Thanks for all the helpful replies. In summary, use chomp
instead of chop. And don't add newlines to an array - just
add them to the file you are writing the array to.
I did get syntax errors with some of the recommendations:
For example:
print DAT "$_\n" foreach @raw_data;
and:
{
local $" = "\n";
print DAT "@raw_data\n";
}
and:
print DAT "$_\n" for @raw_data;
But:
foreach (@raw_data) {
print DAT "$_\n";
}
Seems to work fine, no syntax errors and does what I want...
As for my code looking suspiciously C-like - well that hurts! :-)
||Rich
------------------------------
Date: 28 Jun 2001 10:35:08 -0700
From: Richard Wellum <rwellum@irp-view5.cisco.com>
Subject: Re: Newbie question: What's the opposite of chop?
Message-Id: <y5auithgjynn.fsf@irp-view5.cisco.com>
Thanks - it worked except I needed to add the file handler:
foreach (@raw_data) {
print DAT "$_\n";
}
||Rich
------------------------------
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 1210
***************************************