[25825] in Perl-Users-Digest
Perl-Users Digest, Issue: 8062 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon May 9 18:05:29 2005
Date: Mon, 9 May 2005 15:05:05 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Mon, 9 May 2005 Volume: 10 Number: 8062
Today's topics:
Re: can I modify a file without using a temporary file <tadmc@augustmail.com>
Re: file locking xhoster@gmail.com
Re: How can I prevent perl from exiting during a networ <jgibson@mail.arc.nasa.gov>
Inserting & Updating from txtx to a database! <hackeras@gmail.com>
Media Lending Library - web based application <mdetomaso@bak.rr.com>
Re: Media Lending Library - web based application <noreply@gunnar.cc>
Re: Media Lending Library - web based application <emschwar@pobox.com>
Re: running a compiled program in perl <tadmc@augustmail.com>
Re: The Perl Review, Summer 2005 <comdog@panix.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Mon, 9 May 2005 08:30:50 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: can I modify a file without using a temporary file
Message-Id: <slrnd7upga.6jo.tadmc@magna.augustmail.com>
Lin Jingxian <cckk_lin@yahoo.ie> wrote:
> I want to modify contents of a file.
perldoc -q file
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?
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 09 May 2005 17:24:43 GMT
From: xhoster@gmail.com
Subject: Re: file locking
Message-Id: <20050509132443.553$CR@newsreader.com>
"Tim Neukum" <timothy.w.neukum@boeing.com> wrote:
> i have a three programs that run concurrently: call them daemon, user1,
> user2 on a unix machine SunOS 5.9
>
> daemon is long running as the name implies
> it reads and writes to a file that represents a queue
> something like this:
>
> open (QFILE ">+ $queue_file") or die "daemon ERROR: open: $! died";
You've just blown away your file. Is that what you want to do?
> flock (QFILE, LOCK_EX) or die "daemon ERROR: flock: $! died";
> seek (QFILE, 0, 0) or die "daemon ERROR: seek: $! died";
> # process file
> truncate(QFILE, 0) or die "daemon ERROR: truncate: $! died";
> seek (QFILE, 0, 0) or die "daemon ERROR: seek: $! died";
> # rewrite file
Nowhere here do you give up your lock. If you don't care what is in the
file at start up time, and don't let anyone else access while you are
running, what is the point of having it? If it does give up the lock, then
you have failed to show us something important.
> at prompt> addToQueue job
> adding things to the queue file are implemented with exclusive locking
> this functionality works fine and has for some time with
>
> here's my problem.
> user1 is a process started in the background by addToQueue that monitors
> the job while it is still in the queue
> user2 is another process started in the background by addToQueue that
> monitors the job while it is still in the queue
>
> both read the queue file but i want to have a stable state of the file
> when reading, but i get bad file number when i try to flock
...
> sub inQueue {
> open (INFILE, "< $queue_file") or die "user# ERROR: open: $! died";
> flock (INFILE, LOCK_EX) or die "user# ERROR: open: $! died";
> <<-----------this is the culprit
Some OSes don't let you take an exclusive lock on a file opened
only for reading. Sad, but true.
> QUESTIONS:
> i've seen that sysopen may be prefered to open for writing, Why? eg
> sysopen (QFILE "$queue_file" O_RDWR) or die...
The main reason I see for using it is to avoid race conditions when you
want to be assured the file does not (or does) exist before (re)creating
it. I don't see that that applies to your current situation.
>
> why can't i request a LOCK_EX in sub inQueue??
Because your OS won't let you do that on a opened-for-read file.
> if i change inQueue to LOCK_SH....
> if i have two processes using LOCK_SH will they attempt to read at the
> same time?
Yes. Do you (think you) have a problem with that? If so, why?
> will LOCK_EX ever get a chance??
That depends on the details of your code, which we don't see.
> ie will shared locks always succeed if
> another process has a shared lock even if another process is was waiting
> for an exclusive lock
That is entirely up to your OS, and is not up to Perl. I think the answer
is "yes" on most or all OSes/filesystems, but I don't know. (For what it is
worth, on Mysql, at least older versions that I am used to, it is not the
case. I.e. by default a pending exclusive request will block incoming
shared requests.)
> scenario timeline:
> time 0 user1 requests LOCK_SH
> time 1 user1 gets LOCK_SH
> time 2 daemon requests LOCK_EX
> time 3 daemon waits for os to give lock
> time 4 user2 requests LOCK_SH
> time5 ....does user2 get lock? or does it get in line behind daemon.
Turn the above into Perl, and test it on your OS, using the filesystem
you want to use. See what it does.
>
> if the latter, what the $$$$ is the difference between LOCK_SH and
> LOCK_EX????
One is shared and the other is exclusive. I don't know what part of that
you don't understand, so I don't know how to explain it to you.
> if the former (ie user2 gets LOCK_SH without waiting) then how can you be
> certain of the position, interaction within file stream considering user1
> may be reading?
The system (or perl, or something, anyway) does that for you.
> does each process get a
> different pointer into the file position?
That is certainly the case on the systems I use.
Xho
--
-------------------- http://NewsReader.Com/ --------------------
Usenet Newsgroup Service $9.95/Month 30GB
------------------------------
Date: Mon, 09 May 2005 09:21:33 -0700
From: Jim Gibson <jgibson@mail.arc.nasa.gov>
Subject: Re: How can I prevent perl from exiting during a network error?
Message-Id: <090520050921330579%jgibson@mail.arc.nasa.gov>
In article <fabd4f77.0505080732.428a101a@posting.google.com>, Song
Lining <songlining@gmail.com> wrote:
> Hi, guys
>
> Got a very frustrating problem while writing a perl socket client to
> connect to a server.
>
> The perl client will quit by itself everytime I stop the server and
> the errno is either "ECONNRESET: Connection aborted" or "ECONNABORTED:
> Connection reset by peer". The problem is that I need to keep the
> client alive even the server is shutdown, so I tried to ignore all the
> signals in %SIG but that didn't help either. Here's a snipet of the
> code:
[ client code snipped ]
You cannot keep a socket connection alive if the other host involved
has closed it. You need to trap and detect this error and repeat the
connect step. Implement your client accordingly and keep trying to
connect until you either succeed or give up. Put a time delay between
connection attempts so that you don't hog the network and inadvertantly
create a denial-of-service attack. Intelligent clients will start with
a short delay and increase it for each unsuccessful attempt, up to some
maximum.
Good luck.
----== Posted via Newsfeeds.Com - Unlimited-Uncensored-Secure Usenet News==----
http://www.newsfeeds.com The #1 Newsgroup Service in the World! >100,000 Newsgroups
---= East/West-Coast Server Farms - Total Privacy via Encryption =---
------------------------------
Date: Mon, 09 May 2005 23:51:03 +0300
From: Nikos <hackeras@gmail.com>
Subject: Inserting & Updating from txtx to a database!
Message-Id: <d5oifl$nll$1@nic.grnet.gr>
This is the best i can do with my games.pl script to load the game,
description and times downloaded from a .txt file to database.
Can you suggest something better?
my $dbh = DBI->connect('DBI:mysql:nikos_db', 'root', 'tiabhp2r') or
{RaiseError=>1};
#===============================================================================
my @row;
my $insert = $dbh->prepare( "INSERT INTO games (gamename, gamedesc,
gamecounter) VALUES (?, ?, ?)" );
my $update = $dbh->prepare( "UPDATE games SET gamedesc=? where
gamename=?" );
open (FILE, "<../data/games/descriptions.txt") or die $!;
while (<FILE>) {
chomp;
my ($gamename, $gamedesc) = split /\t/;
$insert->execute( $gamename, $gamedesc, 0 );
if ($DBI::err)
{
print "Error on INSERT $gamename: $DBI::errstr\n";
$update->execute( $gamedesc, $gamename );
if($DBI::err)
{
print "Unable to UPDATE $gamename: $DBI::errstr\n";
}
}
}
close (FILE);
--
"Of course I cant stop you. And that would really bum me out
if that were my job. But my job isnt to stop you, its to
make it as difficult as possible, for as many as possible,
for as long as possible ."
------------------------------
Date: Mon, 09 May 2005 21:29:44 GMT
From: "Michael De Tomaso" <mdetomaso@bak.rr.com>
Subject: Media Lending Library - web based application
Message-Id: <cDQfe.32883$Au1.27491@tornado.socal.rr.com>
2:12 PM 5/9/2005 ... Media Lending Library - web based application
----------------
Q: I'm looking for a PHP-MySQL web solution for a Media Lending Library that
would allow folks to request, check in/out, Library items, etc. ???
Note: the Media, might be Books, CDs, DVDs, etc.
-----
--
thanks & take care M.D.
<aka>
_ _
| |_ ___ _ __ ___ __ _ | |_ ___ ___
| __| / _ \ | '_ ` _ \ / _` | | __| / _ \ / _ \
| |_ | (_) | | | | | | | | (_| | | |_ | (_) | | __/
\__| \___/ |_| |_| |_| \__,_| \__| \___/ \___|
( .) ( .) (o ) (o )
You say tomato and I say tomatoe, Let's call the whole thing off
------------------------------
Date: Mon, 09 May 2005 23:39:35 +0200
From: Gunnar Hjalmarsson <noreply@gunnar.cc>
Subject: Re: Media Lending Library - web based application
Message-Id: <3ea3vtF1top7U1@individual.net>
Michael De Tomaso wrote:
> Q: I'm looking for a PHP-MySQL web solution
Why are you posting about it here?
--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
------------------------------
Date: Mon, 09 May 2005 15:36:51 -0600
From: Eric Schwartz <emschwar@pobox.com>
Subject: Re: Media Lending Library - web based application
Message-Id: <etod5s0uln0.fsf@wilson.emschwar>
"Michael De Tomaso" <mdetomaso@bak.rr.com> writes:
> 2:12 PM 5/9/2005 ... Media Lending Library - web based application
> ----------------
>
> Q: I'm looking for a PHP-MySQL web solution for a Media Lending Library that
> would allow folks to request, check in/out, Library items, etc. ???
And you ask this in a newsgroup about writing Perl programs because...?
> Note: the Media, might be Books, CDs, DVDs, etc.
That's nice. If you want to write such a thing in Perl, give it a
shot, and we'd be glad to help you out with it. If all you want is to
find such a thing, well, there's always Google. Either way, we don't
do PHP anything here.
-=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: Mon, 9 May 2005 08:34:34 -0500
From: Tad McClellan <tadmc@augustmail.com>
Subject: Re: running a compiled program in perl
Message-Id: <slrnd7upna.6jo.tadmc@magna.augustmail.com>
Bob Then <Bob_then@yahoo.com.au> wrote:
> How can I run a compiled C program in Perl
^^^^^^^^^^
How the program was created is irrelevant.
There are essentially 3 ways to run external programs from within Perl:
perldoc -f system
perldoc -f qx
perldoc -f open
See also:
perldoc -q STDERR
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Mon, 09 May 2005 16:50:39 -0500
From: brian d foy <comdog@panix.com>
Subject: Re: The Perl Review, Summer 2005
Message-Id: <090520051650391392%comdog@panix.com>
In article <Xns964C24BF3C8castleamber@130.133.1.4>, John Bokma
<john@castleamber.com> wrote:
> brian d foy wrote:
>
> > Prices: $16 in the US, $30 outside the US. Web only subscriptions
> > are $16. If we can get enough subscribers in the European Union, we'll
> > start printing there too and lower the cost.
> I just wonder how many people will perceive this as a commercial message...
People may perceive that, but this is really a community project. I'd
love to give it away from free, it it actually incurs costs, and I only
charge what I need to pay the bills. No one gets any money for their
work on TPR.
I did think about this issue quite a bit though, and I'm completely
aware on the non-commercial nature of usenet. However, Jon Orwant had
the same sort of advertisements for TPJ during its time and it didn't
seem to be a problem. It also wasn't a problem for the two years we did
PDF-only issues and gave them away for free.
At most, you'll see four of these messages a year, and I'm only sending
them to two groups. In each group, I have a long posting history
(although I've been less frequent lately) and have given quite a bit
of free time to helping others. I think that might let those four
messages a year squeak by. :)
--
brian d foy, comdog@panix.com
Subscribe to The Perl Review: http://www.theperlreview.com
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
#The Perl-Users Digest is a retransmission of the USENET newsgroup
#comp.lang.perl.misc. For subscription or unsubscription requests, send
#the single line:
#
# subscribe perl-users
#or:
# unsubscribe perl-users
#
#to almanac@ruby.oce.orst.edu.
NOTE: due to the current flood of worm email banging on ruby, the smtp
server on ruby has been shut off until further notice.
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
#To request back copies (available for a week or so), send your request
#to almanac@ruby.oce.orst.edu with the command "send perl-users x.y",
#where x is the volume number and y is the issue number.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V10 Issue 8062
***************************************