[15649] in Perl-Users-Digest
Perl-Users Digest, Issue: 3062 Volume: 9
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Tue May 16 14:05:45 2000
Date: Tue, 16 May 2000 11:05:22 -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: <958500321-v9-i3062@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Tue, 16 May 2000 Volume: 9 Number: 3062
Today's topics:
Re: "bind: Invalid argument" makes me say "huh?" <gellyfish@gellyfish.com>
"If" Not Being Evaluated - Vars Are Being Subsituted? <nospam@nospam.com>
Re: "If" Not Being Evaluated - Vars Are Being Subsitute <tina@streetmail.com>
Re: "If" Not Being Evaluated - Vars Are Being Subsitute <mjcarman@home.com>
Re: "If" Not Being Evaluated - Vars Are Being Subsitute nobull@mail.com
=?X-UNKNOWN?Q?Re=3A_Max=EDmum_length_of_perl_strings_an <rootbeer@redcat.com>
@html mailer <contact@superb.ch>
Re: [Hash] Is the key always double-quoted? <rootbeer@redcat.com>
Re: [OT] Reading and Writing to a file <mjcarman@home.com>
Re: Access from several Perl-Scripts on one variable? <pinin@xchain.com>
Re: accessing files via Perl on SuSe 6.4 <ah@datapharm.de>
Re: Accurate IP return? (Abigail)
Any idea how i can do this? I need to insert a link aft <wesleys@globeset.com>
backup file (Jimtaylor5)
Re: backup file nobull@mail.com
carriage returns <s.wiersma01@chello.nl>
Re: Compress::Zlib <rootbeer@redcat.com>
converting array of arrayrefs to hash wisecounselor@my-deja.com
Re: converting array of arrayrefs to hash bsmith@webnetint.com
Re: counter <edbubbleluk@hotmail.com>
Re: counter (Abigail)
Re: counter <thepoet1@arcormail.de>
Re: counter <thepoet1@arcormail.de>
curses - how to ? <markp@mail1.jpl.nasa.gov>
Re: CVS for perl projects (Jerome O'Neil)
Re: CVS for perl projects <jeanphil@sitepak.com>
Re: CVS for perl projects (Jerome O'Neil)
Digest Administrivia (Last modified: 16 Sep 99) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Tue, 16 May 2000 16:05:57 GMT
From: Jonathan Stowe <gellyfish@gellyfish.com>
Subject: Re: "bind: Invalid argument" makes me say "huh?"
Message-Id: <FleU4.1521$Kc1.206703@news.dircon.co.uk>
On 15 May 2000 22:34:51 GMT, Eli the Bearded Wrote:
> I posted a question based on this last week and (tweaking Net::DNS)
> and got no response. So I thought maybe I should ask it better.
>
> Below is a small script that demonstrates the problem. When I
> run it (5.005_03 on Linux and 5.004_03 on SunOS4) I get the
> following error:
>
> bind: Invalid argument at test-bind.pl line 28.
>
> The use of bind on line 28 looks quite reasonable to me.
>
> #!/usr/local/bin/perl5.00403 -w
> # Test bind problem
> use strict;
>
> use Socket;
> use IO::Socket;
> use IO::Select;
>
> use vars qw ( $each $eport $sport @hosts );
>
> $sport = 13579;
> $eport = 2468;
>
> @hosts = qw( 127.1 172.24.1.100 );
>
>
> foreach $each (@hosts) {
>
> my $sock =
> IO::Socket::INET->new(PeerAddr => $each,
> PeerPort => $eport,
> Proto => "udp");
> if ($sport and $sock) {
> $sock->setsockopt(SOL_SOCKET,SO_REUSEADDR, pack('l', 1))
Cant you use :
Reuse => 1
in the constructor options rather than calling setsockopt ?
/J\
------------------------------
Date: Tue, 16 May 2000 16:42:01 +0100
From: "NoSpam" <nospam@nospam.com>
Subject: "If" Not Being Evaluated - Vars Are Being Subsituted?
Message-Id: <IZdU4.1517$Kc1.206759@news.dircon.co.uk>
Hi,
I have added the following statement to a Perl script, but instead of the if
being evaluated it is returned to the HTML page with $number resolved.
How do I get the IF to evaluate?
if ($number eq "3") {
<IMG SRC="test.jpg" BORDER=0 ALT="Test">
}
produces when the script is run and displayed in a browser...
if 1 eq "3") { image }
(i.e. if is being treated as text and not Perl statement)
TIA
Paul.
------------------------------
Date: Tue, 16 May 2000 12:05:14 -0400
From: Tina Mueller <tina@streetmail.com>
Subject: Re: "If" Not Being Evaluated - Vars Are Being Subsituted?
Message-Id: <392171BA.707418EE@streetmail.com>
hi NoSpam,
NoSpam wrote:
> I have added the following statement to a Perl script, but instead of the if
> being evaluated it is returned to the HTML page with $number resolved.
>
> How do I get the IF to evaluate?
>
> if ($number eq "3") {
> <IMG SRC="test.jpg" BORDER=0 ALT="Test">
> }
>
> produces when the script is run and displayed in a browser...
>
> if 1 eq "3") { image }
that's weird...
post a _little_ bit more code; I can only guess (that the code is in between
print <<EOM;
EOM
or something like that...)
tina
-- tinamue@gmx.net --| _ enter the
http://user.berlin.de/~tina.mueller | __| |___ ___ _ _ ___
---- tina's moviedatabase ----| / _` / _ \/ _ \ '_(_-< of
--search & add comments or reviews--| \__,_\___/\___/_| /__/ perception
------------------------------
Date: Tue, 16 May 2000 11:06:15 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: "If" Not Being Evaluated - Vars Are Being Subsituted?
Message-Id: <392171F7.3F030B8E@home.com>
NoSpam wrote:
>
> I have added the following statement to a Perl script, but instead of
> the if being evaluated it is returned to the HTML page with $number
> resolved.
>
> How do I get the IF to evaluate?
>
> if ($number eq "3") {
> <IMG SRC="test.jpg" BORDER=0 ALT="Test">
> }
>
> produces when the script is run and displayed in a browser...
>
> if 1 eq "3") { image }
>
> (i.e. if is being treated as text and not Perl statement)
>
Which means that you are outputting code as a double-quoted string. You
didn't stick this in the middle of a multi-line print(), did you?
BTW, you're stringifying $number to do your comparison. It's better (and
easier for perl) to use a numeric comparison:
if ($number == 3) {
#...
}
-mjc
------------------------------
Date: 16 May 2000 17:54:02 +0100
From: nobull@mail.com
Subject: Re: "If" Not Being Evaluated - Vars Are Being Subsituted?
Message-Id: <u9hfbyfnbp.fsf@wcl-l.bham.ac.uk>
"NoSpam" <nospam@nospam.com> writes:
> I have added the following statement to a Perl script,
> (i.e. if is being treated as text and not Perl statement)
Big clue here! Check preceding lines for unterminated quoting
constructs like << or qq.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 16 May 2000 10:48:40 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: =?X-UNKNOWN?Q?Re=3A_Max=EDmum_length_of_perl_strings_and_sy?= =?X-UNKNOWN?Q?stem=28=29_args?=
Message-Id: <Pine.GSO.4.10.10005161045000.25459-100000@user2.teleport.com>
On Tue, 16 May 2000 herbertka@my-deja.com wrote:
> What is the maxmium length of ActiveState perl strings
Nothing special about ActiveState here. But how much (virtual) memory do
you have? :-)
> and strings that are currently passable as arguments in a system()
> command to the windows (NT) operating system ?
If this is not documented somewhere (and it should be, in some docs for
Windows) you could probably make a test program which would do something
like this:
my $command = 'echo 67890' . ('1234567890' x 50);
Good luck with it!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 16 May 2000 16:52:48 +0200
From: widmer <contact@superb.ch>
Subject: @html mailer
Message-Id: <B5472D60.1E1A%contact@superb.ch>
i was searching for a solution to create a mailing list and send html based
emails to the subscribers.
i found a perfect fitting script at http://www.cgishack.com/mailer/.
the order section of cgishack is down until september 2000, that is too long
to wait for me. if anybody provides me with that particular script or at
least a solution to send html based emails (with working formular fields) to
a mailinglist, i would be very pleased.
i thank you in advance.
pascal
------------------------------
Date: Tue, 16 May 2000 09:55:36 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: [Hash] Is the key always double-quoted?
Message-Id: <Pine.GSO.4.10.10005160951330.25459-100000@user2.teleport.com>
On 16 May 2000, Villy Kruse wrote:
> Would it be correct to interpret 01 as a octal number and not a
> bareword that would be treated as a string between {} or before => ?
Good question. Let's see:
$ perl -MO=Deparse -e '$hash{01} = [ 01=>01 ];'
-e syntax OK
$hash{1} = [1, 1];
> It looks like a number, therefore it is a number, or is this wrong?
I'd have to say that, based upon the evidence, you're right. Of course,
this is as it should be; only barewords (alphanumerics and underscores,
not starting with a digit) should be quoted as hash keys or to the left of
the big arrow.
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 16 May 2000 09:27:12 -0500
From: Michael Carman <mjcarman@home.com>
Subject: Re: [OT] Reading and Writing to a file
Message-Id: <39215AC0.60D9A835@home.com>
Xah wrote:
>
> In the art of flame war, [...]
We don't want your flame war, thank you. We're here to talk about Perl,
and how to use it to solve all sorts of problems.
> Andrew N. McGuire wrote:
> > [ aside to Xah: lists can have duplicate elements, sets can't,
> > by definition ]
>
> Does it subtract any meaning from that paragraph i wrote? (and do
> you think i don't know that?)
If you know the difference between a set and a list, why intermix the
terminology? That only serves to confuse/mislead people, and lower your
credibility with those who understand the distinction.
> Argue with people's head, not their mouth.
I have no idea what's in your head, I can only know what your mouth has
said (or fingers typed). Therefore, I must assume that you are
articulate enough to say what you mean, and will judge you accordingly.
> Godzilla's problem, is largely the same problem i face when dealing
> with Perl peddlers. Ideas fly over their heads, but they bog you down
> with petty details and artless slobber. The Perl mongers and unix
> weenies, think that their stupid naming of programs and pathetic
> syntax makes them giant poets. I see pubescent laddies playing with
> their peckers for the first time.
And your attitude is so similar to hers; I wonder if there's a
connection?
Calling people names and belittling their intelligence is not going to
make them treat you better or give you respect. It's no wonder that
you've rapidly found your way into people's killfiles. If you want to be
taken seriously and given any measure of respect then you must earn it
by acting maturely and capably.
If you're here to bask in self-adoration and sling insults (which,
deliberately or not, is the attitude you are projecting) then prepare to
be killfiled and/or ignored, as we have better things to do with our
time than entertain you.
> "I love bondage and discipline languages. <wink wink, geek girls>"
Well, there's always Ada.
-mjc
------------------------------
Date: Tue, 16 May 2000 20:00:04 +0300
From: pinin <pinin@xchain.com>
Subject: Re: Access from several Perl-Scripts on one variable?
Message-Id: <39217E94.4BE6F913@xchain.com>
Thorsten wrote:
> Is it possible to access from several Perl-Scripts on one variable?
>
> I would be really glad if you could answer me that question and how to do
> so, because this would mean to me to save several hours of work.
>
> Thank you very much!
If you run on UNIX try shared memory
------------------------------
Date: Tue, 16 May 2000 19:14:59 +0200
From: Andreas Huber <ah@datapharm.de>
Subject: Re: accessing files via Perl on SuSe 6.4
Message-Id: <39218213.740D39D3@datapharm.de>
Toni wrote:
> Hy, (this might be a little off-topic, but i would appreciate any help)
> I'd like to open a file like this
> open (FILETHING, "spinach.txt");
>
> but everything my Apache error log tells me, that it can not
> open the file. I can even
> open (FILETHING, "/usr/local/httpd/cgi-bin/spinach.txt");
> and it doesn´t change. And even after chmod´ing everything i can
> get hold of to 777 STILL NO CHANGE.....
>
> Where is the misstake ? (Do I need to say that i am a newbie to Linux ?)
> Do i have to set any rights for file access in apache config ?
> I did not modify anything yet (at least i think so).
> It is the default installation that i am using.
>
> Please help me, because i´m already going mehari.....
is the script-path in httpd.conf right?
--
Andreas Huber
Produktion & Entwicklung
Datapharm Netsystems AG
E-Mail: ah@datapharm.de
Tel.: (+49) 89 85 68 4 -156
Fax: (+49) 89 85 68 4 -100
------------------------------
Date: 16 May 2000 17:10:02 GMT
From: abigail@foad.org (Abigail)
Subject: Re: Accurate IP return?
Message-Id: <slrn8i307a.p3i.abigail@ucan.foad.org>
On Mon,
15 May 2000 22:39:04 +0100, [TNN]G.Bloke <GBloke@actiongames.co.uk> wrote:
++ Is there a reliable method to return a users IP address?
No. It's not even well defined. IP addresses aren't associated with
users - IP addresses are associated with interfaces.
There can be thousands of computers hiding behind the same interface.
And one computer can have 20 interfaces, each interface having several
IP addresses. Furthermore, firewalls routinely change IP addresses
on the packets they pass through.
Of course, none of this has anything to do with Perl.
Abigail
------------------------------
Date: Mon, 15 May 2000 16:02:55 -0500
From: "Wes" <wesleys@globeset.com>
Subject: Any idea how i can do this? I need to insert a link after or before a
Message-Id: <8fpp6f$5bd$2@onion.globeset.com>
Any idea how i can do this? I need to insert a link after or before a
specific link.
------------------------------
Date: 16 May 2000 15:44:52 GMT
From: jimtaylor5@aol.com (Jimtaylor5)
Subject: backup file
Message-Id: <20000516114452.26656.00003436@ng-cf1.aol.com>
Help! I'm trying to write an effective backup to keep my file data from getting
corrupted. This is what I have:
open (MYPAGE,"$dat")
flock MYPAGE, 2;
@lines = <MYPAGE>;
flock MYPAGE, 8;
close(MYPAGE);
open (BAK, ">$datbak")
flock BAK, 2;
if ($misl == 1) {
#do something
}
flock BAK, 8;
close (BAK);
use File::Copy;
copy ("$datbak", "$dat");
My questions are, is this sufficient to keep my data from becoming corrupted
if someone quits in the middle? Can two users simultaneously using it cause
copy to ruin the file original file, or can you give me an example of a better
way of backing up a file. Or is this one fine ? Thanks in Advance for your
help.
------------------------------
Date: 16 May 2000 18:02:28 +0100
From: nobull@mail.com
Subject: Re: backup file
Message-Id: <u97lcufmxn.fsf@wcl-l.bham.ac.uk>
jimtaylor5@aol.com (Jimtaylor5) writes:
> Help!
Please read the FAQ before you ask qestions here.
Your question is very similar to:
How do I change one line in a file/delete a line in a file/insert a
line in the middle of a file/append to the beginning of a file?
> I'm trying to write an effective backup to keep my file data from getting
> corrupted.
Looking at your code I'd say that's not what you are doing. You
appear to be trying to do an inplace edit.
> This is what I have:
>
> open (MYPAGE,"$dat")
> flock MYPAGE, 2;
> @lines = <MYPAGE>;
> flock MYPAGE, 8;
> close(MYPAGE);
> open (BAK, ">$datbak")
> flock BAK, 2;
> if ($misl == 1) {
> #do something
> }
> flock BAK, 8;
> close (BAK);
> use File::Copy;
> copy ("$datbak", "$dat");
That won't compile.
You are using a very odd indenting convention.
You don't check return values on open().
You put redundant double qoutes arround scalars.
You use literal values in flock() rather than the defined sybolic
constants.
You assume File::Copy::copy is atomic - it is not.
You slurp the whole file into an array - this may be necessary but
usually it is not.
You release locks too soon.
> My questions are, is this sufficient to keep my data from becoming corrupted
> if someone quits in the middle?
No. The only way to do that is to ensure the update is atomic. The
way to atomically replace one file with another is rename().
You may also want to lock to prevent two simulateous updates. If you
don't the file won't be corrupted but one of the two updates will be
lost.
> Can two users simultaneously using it cause copy to ruin the file
> original file,
Yes. There is no point locking something if you don't hold onto lock for
the entire duration of the transaction.
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Tue, 16 May 2000 17:59:56 GMT
From: "Wybo Wiersma" <s.wiersma01@chello.nl>
Subject: carriage returns
Message-Id: <w0gU4.2812$No1.22673@flipper>
If I upload my scripts to the server in ascii mode, then They always seem to
contain carriage returns which results the scripts in crashing. Is there
some easy way to prevent this ?
------------------------------
Date: Tue, 16 May 2000 09:19:34 -0700
From: Tom Phoenix <rootbeer@redcat.com>
Subject: Re: Compress::Zlib
Message-Id: <Pine.GSO.4.10.10005160916420.25459-100000@user2.teleport.com>
On Tue, 16 May 2000 jake0641@my-deja.com wrote:
> use Compress::Zlib;
> open(ZFILE, "access_log.1.gz") or die "problem:
> $!";
> my $zfile=<ZFILE>; #assuming no line breaks
> in .gz files?
Bad assumption. You should probably use binmode, and you should assume
that the newline character will probably show up somewhere in any binary
file, sooner or later. Try perl's read() function.
> This doesn't produce an error, but prints nothing.
Did you remember to turn on warnings?
> >It might be more convenient to open
> >RAWDATA, "gzip -dc '$filename' |" or die "can't
> >open pipe on $filename: $!".
>
> Is this safe for CGI?
In general, no. But it could be done safely. Still, the module should make
this work.
> Am I just doing something wrong with the uncompress($source) function?
My sources say "yes". :-)
Cheers!
--
Tom Phoenix Perl Training and Hacking Esperanto
Randal Schwartz Case: http://www.rahul.net/jeffrey/ovs/
------------------------------
Date: Tue, 16 May 2000 15:33:44 GMT
From: wisecounselor@my-deja.com
Subject: converting array of arrayrefs to hash
Message-Id: <8frpon$bdr$1@nnrp1.deja.com>
I have an array of hashrefs representing rows in a dataset, where each
row is a hashref, keys are column names, values are data. In the
dataset, one column, "name", will have the same value several times,
representing a group of menu items in an application, such as File -
Open, File - New, etc. I need to iterate over this data structure and
create html-based menus, where I start with an "empty" html
menu-submenu type template when I detect a change in the value of the
"name" column. The rows are already sorted by the "name" column using
sql statement. I tried to turn it into a single hash, whose keys are
are the value from each hashref's keyed element 'name'. I wanted to
turn
[
{ "name" => "name_value1", "key2" => "val2", ...}
{ "name" => "name_value2", "key2" => "val2", ...}
]
into
{ "name_value1" => [ { original hashref 1} ],
"name_value2" => [ { original hashref 2} ]
}
so I could just iterate over keys of this one hash, and then go through
the arrayref which should have the rows of data for that key. Is there
an easier way to do the whole thing, or at least a way to transform the
data, my way doesn't work, the first value of "name" works, but the
remaining keys only get one value where they should have many values.
brian
my $seen;
my %menus; # the new hash
# $m is an arrayref of hashrefs
for my $item (@$m)
{
if($seen ne $item->{name})
{
$menus{ $item->{name} } = [ $item ];
}
else
{
push @{ $menus{$item->{name}} }, $item;
}
$seen = $item->{name};
}
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 16 May 2000 15:46:12 GMT
From: bsmith@webnetint.com
Subject: Re: converting array of arrayrefs to hash
Message-Id: <8frqfu$cga$1@nnrp1.deja.com>
I realized I had error in sql statement which fixed my problem.
However, I would appreciate feedback on whether there is a better way to
do what I'm doing. I suspect mine is slow, since I have to iterate over
my dataset, transform it to a new hash, and iterate again.
thanks for any help
brian
In article <8frpon$bdr$1@nnrp1.deja.com>,
wisecounselor@my-deja.com wrote:
> I have an array of hashrefs representing rows in a dataset, where each
> row is a hashref, keys are column names, values are data. In the
> dataset, one column, "name", will have the same value several times,
> representing a group of menu items in an application, such as File -
> Open, File - New, etc. I need to iterate over this data structure and
> create html-based menus, where I start with an "empty" html
> menu-submenu type template when I detect a change in the value of the
> "name" column. The rows are already sorted by the "name" column using
> sql statement. I tried to turn it into a single hash, whose keys are
> are the value from each hashref's keyed element 'name'. I wanted to
> turn
>
> [
> { "name" => "name_value1", "key2" => "val2", ...}
> { "name" => "name_value2", "key2" => "val2", ...}
> ]
>
> into
>
> { "name_value1" => [ { original hashref 1} ],
> "name_value2" => [ { original hashref 2} ]
> }
>
> so I could just iterate over keys of this one hash, and then go
through
> the arrayref which should have the rows of data for that key. Is
there
> an easier way to do the whole thing, or at least a way to transform
the
> data, my way doesn't work, the first value of "name" works, but the
> remaining keys only get one value where they should have many values.
>
> brian
>
> my $seen;
> my %menus; # the new hash
>
> # $m is an arrayref of hashrefs
>
> for my $item (@$m)
> {
> if($seen ne $item->{name})
> {
> $menus{ $item->{name} } = [ $item ];
> }
> else
> {
> push @{ $menus{$item->{name}} }, $item;
> }
> $seen = $item->{name};
> }
>
> Sent via Deja.com http://www.deja.com/
> Before you buy.
>
Sent via Deja.com http://www.deja.com/
Before you buy.
------------------------------
Date: Tue, 16 May 2000 12:13:09 -0400
From: "Ed" <edbubbleluk@hotmail.com>
Subject: Re: counter
Message-Id: <8frrr4$8sm$1@nntp9.atl.mindspring.net>
Hi Gang,
I tried to run this code which is above from Christian (I copied it below
for you to see) and it does not work, I get premature end of script headers,
can anybody help?
The code from malverian works, but it does not increment the counter and
always is at 0
Thanks
Ed
#!/usr/bin/perl -w
#
# This script is written by Chr. Winter <thepoet1@thepoet1.de>
# It is based on a script from edbubbleluk@hotmail.com
# This script is freeware. Feel free to use, modify and distribute
# it.
#
# You can download this script at
# http://www.linux-config.de/cgi-bin/shlpage.cgi?page=scripts.html&txt=no
#
use CGI;
use CGI::Carp qw(fatalsToBrowser);
use Fcntl qw(:flock);
my @visitors;
my @dates;
my $hitsfile = "/home/httpd/hits.dat"; # or somewhere else
my $visitorsfile = "/home/httpd/visitors.dat"; # or somewhere else
# The two files hits.dat and visitors.dat should be created before
# starting the script the first time, hits.dat containing nothing
# but a zero (0) char.
#
# Best would be to put both .dat-files out of the web-reachable
# directory, e.g. if you have a virtual account at a server rooted
# at /home/~username/WWW then put it under /home/~username and
# give this paths to the script.
#
# chmod them to 644 (rw-r--r--) and chown them to user www, httpd
# or nobody if none of the first two is available.
my $expires_after = 2 * 3600; # 2 hours = 2 * 3600 seconds
my $query=new CGI;
open( HIT, "+<$hitsfile" ) or die $!;
sleep 1 until (flock HIT, LOCK_EX);
# lock the file, otherwise counter could be incremented by other
# visitors and then set to a value too low by this one
my $hitcount = <HIT>;
chomp $hitcount;
open( VIS, "+<$visitorsfile" ) or die $!;
sleep 1 until (flock VIS, LOCK_EX);
# same here, but effects of two scripts writing simultaneosly
# could be even worse.
while (<VIS>)
{
my ($date, $name) = split '==', $_;
if( time-$date < $expires_after )
{
# only compare entries that haven't yet expired!
push @visitors, $name;
push @dates, $date;
}
}
chomp @visitors;
if ( @visitors && "@visitors" =~ /$ENV{"REMOTE_ADDR"}/)
{
# 'if ( @visitors &&' is tested because visitors.dat may be empty
# at the first run
foreach( 0..$#visitors )
{
# update user entry to actual time as last visit
$dates[$_] = time if ( $visitors[$_] eq $ENV{"REMOTE_ADDR"} );
}
flock HIT, LOCK_UN;
close HIT;
}
else
{
push @visitors, $ENV{"REMOTE_ADDR"};
push @dates, time;
$hitcount++;
seek( HIT, 0, 0 );
print HIT $hitcount;
flock HIT, LOCK_UN;
close HIT;
}
seek( VIS, 0 , 0 );
foreach( 0..$#visitors )
{
# rewrite all visitors into file
print VIS "$dates[$_]==$visitors[$_]\n";
}
flock VIS, LOCK_UN;
close VIS;
print $query->header(),"\n\n";
print $hitcount;
exit 0;
------------------------------
Date: 16 May 2000 17:05:48 GMT
From: abigail@foad.org (Abigail)
Subject: Re: counter
Message-Id: <slrn8i2vvc.p3i.abigail@ucan.foad.org>
On Tue, 16 May 2000 12:13:09 -0400, Ed <edbubbleluk@hotmail.com> wrote:
++
++ I tried to run this code which is above from Christian (I copied it below
++ for you to see) and it does not work, I get premature end of script headers,
++ can anybody help?
Then you have a bug.
Abigail
------------------------------
Date: Tue, 16 May 2000 16:02:59 +0200
From: Christian Winter <thepoet1@arcormail.de>
Subject: Re: counter
Message-Id: <jekrf8.44q.ln@usenet-autoren.de>
Abigail <abigail@foad.org> wrote:
> On Mon,
> 15 May 2000 22:05:36 +0200, Christian Winter <thepoet1@arcormail.de> wrote:
> ++
> ++ sleep 1 until (flock HIT, LOCK_EX);
> This is strange. Unless told otherwise, flock() will block untill
> it has the lock - or a failure occurs. The only time flock() will
> return false on a blocking call, is when the flock() fails because
> of an error condition; not because it has to wait for a lock. Blindly
> sleeping a second and retrying isn't good.
> flock HIT, LOCK_EX or die "flock failed: $!";
Yes, your mostly right. On the other hand on some broken-POSIX
systems it occured to me that flock only did work after some
retrial. Maybe I should change it to use a costum flock procedure
like
sub my_flock($)
{
my $handle = shift;
my $c=0;
my $lock_result;
until( $lock_result = flock $handle, LOCK_EX || $c == 10 )
{
$c++;
sleep 1;
}
return $lock_result;
}
> ++ if ( @visitors && "@visitors" =~ /$ENV{"REMOTE_ADDR"}/)
> That gets expensive after a while. Why not
> if (grep {$_ eq $ENV {REMOTE_ADDR}} @visitors)
Thanx, I think I'll use that.
> which will neither build a long string, nor uses the regex machine.
> On top of that, it won't create a false positive if @visitors contains
> '127.0.0.100' and $ENV {REMOTE_ADDR} equals '127.0.0.1'.
Yes, again thanx. Just didn't see that, but to my excuse I must say it
was neary midnight when I wrote it :-)
> Of course, using a dbm file would be much more efficient.
It would. Maybe I'll do one with that the next time.
Best greetings
Christian
greetings
Christian
------------------------------
Date: Tue, 16 May 2000 16:10:19 +0200
From: Christian Winter <thepoet1@arcormail.de>
Subject: Re: counter
Message-Id: <bskrf8.44q.ln@usenet-autoren.de>
Larry Rosler <lr@hpl.hp.com> wrote:
> In article <galpf8.8g4.ln@usenet-autoren.de> on Mon, 15 May 2000
> 22:05:36 +0200, Christian Winter <thepoet1@arcormail.de> says...
>> #!/usr/bin/perl -w
> use strict; # But your coding style seems to conform to it already.
Actually I always have it in when writing a program. Just
have to put it out when I test what I wrote on my provider's
host, since he has a broken perl installation (don't know whether
this will change one day :-( ), and there it would give me server
errors.
>> if ( @visitors && "@visitors" =~ /$ENV{"REMOTE_ADDR"}/)
> Perhaps this is a little better: /\b\Q$ENV{REMOTE_ADDR}\E\b/
Yes, your right. But I think I'll use Abigails suggestion, which
doesn't use RegExp at all, what may speed up the whole thing a
little when having quite some adresses to parse.
> Unlocking the file before closing it is not recommended.
Yes, again right. I should remove the unlock also when I take
away the flush. I'll put a pointer to the corrected version
into the group after I have worked the script over.
>> seek( HIT, 0, 0 );
> Test for success.
Will be done.
> Nice job. I'm sure it will make a lot of people happier than some of
> the stuff now posted, such as Matt Wright's golden oldies.
Thanx. I think I'm slowly going to learn "perlish".
Best greetings
Christian
greetings
Christian
------------------------------
Date: Tue, 16 May 2000 10:43:07 -0700
From: Marc Pestana <markp@mail1.jpl.nasa.gov>
Subject: curses - how to ?
Message-Id: <3921889F.E143FD9C@mail1.jpl.nasa.gov>
Can someone help me with a question about the use of the perl module
CURSES
$mySubwin # is a sub window I create using the curses
# function subwin.
$char # character scalar
I'm using the following code to get characters from a F-secure VT100
terminal emulator on a Mac (OS 8.6) client, HP unix host supporting
curses(5).
raw;
noecho;
$char = getch($mySubwin);
move($mySubwin,0,0);
addstr($mySubwin,$char);
refresh($mySubwin);
the output for most keys is as expected. But, the arrow keys produce the
values A,B,C,D. If, however, I use the following code (using getstr
instead of getch)
raw;
noecho;
getstr($mySubwin,$char);
move($mySubwin,0,0);
addstr($mySubwin,$char);
refresh($mySubwin);
the arrow keys produce the following output on my screen: ^[[A, ^[[B,
etc. I need to obtain unique code for these keys. Any ideas.
------------------------------
Date: Tue, 16 May 2000 16:05:11 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: CVS for perl projects
Message-Id: <XkeU4.211$Wh6.12553@news.uswest.net>
In article <39215DC1.67CED0F4@sitepak.com>,
Jean-Philippe Bouchard <jeanphil@sitepak.com> writes:
> Hello,
> We've decided to use CVS to maintain our perl sources tree. We looked
> for perl specific issues but weren't able to find any precedent on the
> web or in the documentation. If you are aware of such project going on
> (using CVS or any other source control software) could you please let us
> know.
I'm not quite sure what your issues would be. Yoy can check perl into
a CVS repository just like any other code.
What exactly is the problem?
------------------------------
Date: Tue, 16 May 2000 13:11:30 -0400
From: Jean-Philippe Bouchard <jeanphil@sitepak.com>
Subject: Re: CVS for perl projects
Message-Id: <39218142.EAA6947A@sitepak.com>
Jerome O'Neil wrote:
>
> In article <39215DC1.67CED0F4@sitepak.com>,
> Jean-Philippe Bouchard <jeanphil@sitepak.com> writes:
> > Hello,
> > We've decided to use CVS to maintain our perl sources tree. We looked
> > for perl specific issues but weren't able to find any precedent on the
> > web or in the documentation. If you are aware of such project going on
> > (using CVS or any other source control software) could you please let us
> > know.
>
> I'm not quite sure what your issues would be. Yoy can check perl into
> a CVS repository just like any other code.
>
> What exactly is the problem?
Well, the problem is that we need to keep the sources live at all time.
So what we do right now is create a dummy checkout where we want the
sources to be and we do update on that checkout everytime a developer
does a commit. This brings a lot of overhead (we have a lot of files in
the repository) and we were wondering if there would be alternative to
this...
--
---------------------------------
Jean-Philippe Bouchard
Sitepak - http://www.sitepak.com/
jeanphil@sitepak.com
---------------------------------
------------------------------
Date: Tue, 16 May 2000 17:24:37 GMT
From: jerome@activeindexing.com (Jerome O'Neil)
Subject: Re: CVS for perl projects
Message-Id: <pvfU4.232$Wh6.16302@news.uswest.net>
In article <39218142.EAA6947A@sitepak.com>,
Jean-Philippe Bouchard <jeanphil@sitepak.com> writes:
> Jerome O'Neil wrote:
>> What exactly is the problem?
> Well, the problem is that we need to keep the sources live at all time.
> So what we do right now is create a dummy checkout where we want the
> sources to be and we do update on that checkout everytime a developer
> does a commit.
Oook. This is a process problem. You solve it by having one person
responsible for the build, and stop checking out code directly into
your production boxes.
Your build manager checks out the latest code, does his magical build
things (packages, tarballs, etc..) for the distribution.
Then you put the new distribution on your production boxes.
> This brings a lot of overhead (we have a lot of files in
> the repository) and we were wondering if there would be alternative to
> this...
If what your doing is a problem, don't do that. :)
Good luck!
------------------------------
Date: 16 Sep 99 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 16 Sep 99)
Message-Id: <null>
Administrivia:
The Perl-Users Digest is a retransmission of the USENET newsgroup
comp.lang.perl.misc. For subscription or unsubscription requests, send
the single line:
subscribe perl-users
or:
unsubscribe perl-users
to almanac@ruby.oce.orst.edu.
| NOTE: The mail to news gateway, and thus the ability to submit articles
| through this service to the newsgroup, has been removed. I do not have
| time to individually vet each article to make sure that someone isn't
| abusing the service, and I no longer have any desire to waste my time
| dealing with the campus admins when some fool complains to them about an
| article that has come through the gateway instead of complaining
| to the source.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
To request back copies (available for a week or so), send your request
to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
where x is the volume number and y is the issue number.
For other requests pertaining to the digest, send mail to
perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
sending perl questions to the -request address, I don't have time to
answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V9 Issue 3062
**************************************