[23454] in Perl-Users-Digest
Perl-Users Digest, Issue: 5669 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Oct 16 09:11:00 2003
Date: Thu, 16 Oct 2003 06:10:11 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Thu, 16 Oct 2003 Volume: 10 Number: 5669
Today's topics:
Re: How to update entries in a file (Tad McClellan)
Re: How to update entries in a file <no@spam.here>
Re: How to update entries in a file <bernard.el-haginDODGE_THIS@lido-tech.net>
Re: How to update entries in a file <no@spam.here>
Re: Is flock Needed for Logs? <flavell@ph.gla.ac.uk>
Re: Perl in Legato AAM <jwillmore@remove.adelphia.net>
Re: Perl scripts for Unix on my windows machine (Anno Siegel)
Re: PPM 'upgrade' command broken? <jwillmore@remove.adelphia.net>
Re: PPM 'upgrade' command broken? <kalinaubears@iinet.net.au>
Re: Strange behaviour with '\r' character [[ sorry my o <nobull@mail.com>
Re: string substitution problem (Tad McClellan)
Re: string substitution problem <dave.nospam@ntlworld.com>
Re: string substitution problem (Anno Siegel)
Re: Threads and OO Question <Ed+nospam@ewildgoose.demon.co.uk@>
XML::Checker::Parser <bhjp@spookyworld.dnsalias.com>
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 15 Oct 2003 22:31:30 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: How to update entries in a file
Message-Id: <slrnbos48i.856.tadmc@magna.augustmail.com>
John <no@spam.here> wrote:
> Actual server.pl code follows.
^^^^^^
I doubt that.
> It is now working
Liars never prosper.
> sub fileupdate {
> open TEST, "test.xml" or die "Could not open test.xml $!\n";
^^^^
> print DATA @lines;
^^^^
> print DATA "\n";
^^^^
> close DATA;
^^^^
> }
One of these things is not like the other, one of these things
just isn't the same...
(and you are opening for input rather than for output...)
> $server = new IO::Socket::INET {
^
^
> LocalAddr => 'localhost:9000',
> Proto => 'tcp',
> Reuse => 1,
> ) or die "Can't setup server $!\n";
^
^
One of these things is not like the other, one of these things
just isn't the same...
> Once again, apologies for the hassles.
Yeah, right.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 16 Oct 2003 07:47:23 GMT
From: "John" <no@spam.here>
Subject: Re: How to update entries in a file
Message-Id: <f2sjb.152860$bo1.96548@news-server.bigpond.net.au>
"Tad McClellan" <tadmc@augustmail.com> wrote in message
news:slrnbos48i.856.tadmc@magna.augustmail.com...
> John <no@spam.here> wrote:
>
> > Actual server.pl code follows.
> ^^^^^^
>
> I doubt that.
>
>
> > It is now working
>
>
> Liars never prosper.
>
>
> > sub fileupdate {
> > open TEST, "test.xml" or die "Could not open test.xml $!\n";
> ^^^^
> > print DATA @lines;
> ^^^^
> > print DATA "\n";
> ^^^^
> > close DATA;
> ^^^^
> > }
>
>
> One of these things is not like the other, one of these things
> just isn't the same...
>
> (and you are opening for input rather than for output...)
>
>
> > $server = new IO::Socket::INET {
> ^
> ^
> > LocalAddr => 'localhost:9000',
> > Proto => 'tcp',
> > Reuse => 1,
> > ) or die "Can't setup server $!\n";
> ^
> ^
>
> One of these things is not like the other, one of these things
> just isn't the same...
>
>
> > Once again, apologies for the hassles.
>
>
> Yeah, right.
>
>
> --
> Tad McClellan SGML consulting
> tadmc@augustmail.com Perl programming
> Fort Worth, Texas
Thanks for pointing out the errors.
As expected, there were typos when I re-typed the code here. I'm sure you
had never done that, right?
Well, I guess some of us ain't perfect.
Anyway, once again with the corrections:
************************
#!/usr/bin/perl -w
use strict;
use IO::Socket;
my ($server);
my (@lines);
sub fileupdate {
open TEST, ">>test.xml" or die "Could not open test.xml $!\n";
print TEST @lines;
print TEST "\n";
close TEST;
}
$server = new IO::Socket::INET (
LocalAddr => 'localhost:9000',
Proto => 'tcp',
Reuse => 1,
) or die "Can't setup server $!\n";
$server->listen();
$server->autoflush(1);
print "Server is waiting for data...\n";
my $data;
while ($data = $server->accept()) {
print "Connected from: ", $data->peerhost();
print " on port: ", $data->peerport(), "\n";
@lines = <$data>;
fileupdate();
print "Connection closed\n";
close $data;
print "Waiting for more data...\n";
}
Feel free to point out any errors you find. After all, I am here to learn.
Having said that, I see this thread coming to an end. I have achieved what I
wanted for now.
I'm sure there'll be more Qs coming.
BTW, in order for me to be a liar you have to prove intent. So until you do
that you have no case. :)
Ohh, and another thing: I will not lose any sleep if you don't feel like
accepting my apologies.
Stay tuned - I'm sure I'll give you plenty of opportunities to have a go at
me later on.
l8r
------------------------------
Date: Thu, 16 Oct 2003 08:11:49 +0000 (UTC)
From: "Bernard El-Hagin" <bernard.el-haginDODGE_THIS@lido-tech.net>
Subject: Re: How to update entries in a file
Message-Id: <Xns9416678AC443Celhber1lidotechnet@62.89.127.66>
"John" <no@spam.here> wrote in:
[...]
> Thanks for pointing out the errors.
> As expected, there were typos when I re-typed the code here. I'm sure
> you had never done that, right?
And you'd be right. I doubt Tad ever re-typed code when he could/should
have copied and pasted. That was the point, not that you made mistakes.
> Well, I guess some of us ain't perfect.
Ain't ain't a word.
> Anyway, once again with the corrections:
[...]
> Feel free to point out any errors you find. After all, I am here to
> learn.
If you are here to learn you should at least make an attempt
at following the guidelines for this group. You repeatedly
post code full of syntax errors claiming it "works", you re-type code,
you repeat questions ignoring correct answers you got to them (on this
group *and* on pl.comp.lang.perl), you insist on quoting sigs and to
top it all off you're rude to people who, in spite of the many
reasons you gave them to killfile your ass, have tried to help
you.
> Having said that, I see this thread coming to an end. I have
> achieved what I wanted for now.
So basically what you're saying is:
"I've stepped on many toes, but I got what I wanted so fsck you."
> I'm sure there'll be more Qs coming.
So basically what you're saying is:
"I've stepped on many toes, but I got what I wanted so fsck you for now,
but I'll be back later to step on your toes some more."
> Ohh, and another thing: I will not lose any sleep if you don't feel
> like accepting my apologies.
But you just might lose Tad's expertise. A shame, really, since Tad knows
his stuff.
> Stay tuned - I'm sure I'll give you plenty of opportunities to have a
> go at me later on.
I think you underestimate Tad's patience (even though it has impressed me
many times during this thread). I don't want to speak for Tad, but I'd be
very surprised if he saw any of your posts after this one.
Bernard
------------------------------
Date: Thu, 16 Oct 2003 12:43:59 GMT
From: "John" <no@spam.here>
Subject: Re: How to update entries in a file
Message-Id: <jowjb.153363$bo1.58613@news-server.bigpond.net.au>
[snipped]
>
>
> I think you underestimate Tad's patience (even though it has impressed me
> many times during this thread). I don't want to speak for Tad, but I'd be
> very surprised if he saw any of your posts after this one.
>
>
> Bernard
Bernard et al,
I admit, I was less than perfect in pursuing my answers.
If that is a crime then I'm 100% guilty.
On the other hand, I would like everyone to know that I'm a newbie.
I have never tried to deny that. If being a newbie is a crime then I'm
guilty as charged.
Maybe I did not take it too well when some ppl made certain
accusations/assumptions.
Well, that's human nature. At least in my case.
And with regard to the code, it was not full of syntax errors. Maybe I had
some typos in there but if you had bothered to correct them then you would
see that my reasoning was correct. For anyone who is willing to challenge
this, I'll be more than happy to provide the original code.
Like I said before, I respect the knowledge ppl have around here and that is
why I asked the Qs in this NG.
No one is forced to reply to my posts. But I would hope that whoever does
reply, is not condescending or patronising.
To some of you, my Qs may seem trivial or even silly. Just try to remember
your first steps. So, once again, if I have offended anyone, I apologise. If
you do not feel like replying then don't waste your time. I'm sure everyone
has better things to do.
Ohh, and by the way Bernard, I'm no trying to step on anyone's toes. So stop
trying to read my mind or put words in my mouth. All I wanted to do is to
end this thread at this point. Maybe, if you have so much to say, you should
have made an attempt to do it earlier.
Enuf said.
JH
------------------------------
Date: Thu, 16 Oct 2003 12:35:51 +0100
From: "Alan J. Flavell" <flavell@ph.gla.ac.uk>
Subject: Re: Is flock Needed for Logs?
Message-Id: <Pine.LNX.4.53.0310161200210.26358@ppepc56.ph.gla.ac.uk>
On Thu, 16 Oct 2003, Public Interest wrote:
(Did you choose that moniker to deliberately irritate, or are you just
not sensitive to the effect?)
[unattributed quote - original poster was Malcolm Dew-Jones:]
> > My understanding is that a single `write()' of less than a certain (fairly
> > large) size is supposed to be atomic on unix (and presumably on linux) -
> > that means atomic relative to other write() calls.
Indeed. A lot of unix-based software appears to rely on the semantics
of opening for append, and atomically appending a record, without
using locking. You can't rely on the *sequence* in which asynchronous
processes write their records, but they don't fragment records and
they don't damage file structure. There's a great deal of software
that would go horribly wrong if that stopped working.
> > I do not think the above is true for windows based machines.
I'm no expert in that area, but I've heard the same.
> So, did you use flock in C or Perl programs? 40-50 copies are a lot...
> What I want to find what is when it is nessary to implement flock and when
> it is taken care automatically.
It's not an issue of quantity, but of logic.
> Again, for my log or ad exchange program, can anyone SHOW me a sample of
> using flock
There's an FAQ, isn't there? perldoc -q lock
http://www.perldoc.com/perl5.8.0/pod/perlfaq5.html#How-can-I-lock-a-file-
and the following sections.
> and give me an idea how many CGI files can wait on a locked file?
By "CGI files" you presumably mean "CGI processes" or something like
that. There's no particular budget of waiting on a lock: as far as I
understand it, if there were the resources available to create the
process, then it can wait. (But in general you need to understand the
logic of what you are doing, in order to avoid creating a deadlock
situation.)
None of this is specific to Perl, by the way.
> I also would like to know what is LOCK_SH, I understand LOCK_EX, but how can
> a lock shared?
There's an FAQ and tutorial, isn't there?
perldoc -q lock ; perldoc perlopentut
http://www.perldoc.com/perl5.8.0/pod/perlopentut.html#File-Locking
> In perldoc -f flock, it also states "To avoid the possibility of
> miscoordination, Perl now flushes FILEHANDLE before locking or
> unlocking it." What is a flush of filehandle?
perldoc -q flush
Read the friendly documentation. Come back with specific questions.
You know it makes sense.
------------------------------
Date: Thu, 16 Oct 2003 04:17:18 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: Perl in Legato AAM
Message-Id: <20031016001741.34e494ee.jwillmore@remove.adelphia.net>
On 15 Oct 2003 11:22:44 -0700
john_hosie@hotmail.com (catfish_face) wrote:
> Legato AAM has a built-in Perl interpreter for processing rules,
> triggers, etc. Does anyone know of anyplace where samples are for
> Perl scripts that might be used with Legato AAM? I'm really trying
> to see if there is some repository in the sky for this sort of
> stuff.
Short answer: no.
Long answer: What is AAM? Backup software? If so, have you checked
out the Legato web site to see if they posted some samples? Or called
support for further direction? Some vendors put out Perl modules or
thier own Perl SDK's, but they are totally unsupported (Remedy, I
think, puts one out, but they tell you straight up that it's a "on
your own" adventure).
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
This is the LAST time I take travel suggestions from Ray
<Bradbury!
------------------------------
Date: 16 Oct 2003 10:40:07 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: Perl scripts for Unix on my windows machine
Message-Id: <bmlsi7$qbt$1@mamenchi.zrz.TU-Berlin.DE>
Ren Patterson <reneap@hotmail.com> wrote in comp.lang.perl.misc:
> Gunnar Hjalmarsson <noreply@gunnar.cc> wrote in message
> news:<bmk5vk$ngmu4$1@ID->
> > My point is that your way of justifying that you hadn't tried revealed
> > an irritating lack of respect to those whose help you were seeking.
>
>
> How in the world does wanting to learn whether it is known for a fact
> that one "type" of script will not work in Windows, before installing
> that very script represent a lack of respect much less irritating?
>
> Have you ever heard of asking before acting? or when in doubt ask?
Oh yes, we've heard that a few times, believe me.
On Usenet, it also matters whom you ask. If you have a question that
a computer can answer, ask the machine first. Your question could be
answered by a computer, but you asked the group first. That is
considered rude.
Anno
------------------------------
Date: Thu, 16 Oct 2003 04:13:35 GMT
From: James Willmore <jwillmore@remove.adelphia.net>
Subject: Re: PPM 'upgrade' command broken?
Message-Id: <20031016001359.1a646d3f.jwillmore@remove.adelphia.net>
On Wed, 15 Oct 2003 21:53:32 GMT
"Eric McDaniel" <NOSPAM@NOSPAM.COM> wrote:
>
> Installation: Win32 ActivePerl 5.8.0.806
<snip>
Try going ActiveState's home page and looking under support. They
have a knowledge base you can search - and submit bug reports if you
can't find the answer to your question.
HTH
--
Jim
Copyright notice: all code written by the author in this post is
released under the GPL. http://www.gnu.org/licenses/gpl.txt
for more information.
a fortune quote ...
*** NEWSFLASH *** Russian tanks steamrolling through New
Jersey!!!! Details at eleven!
------------------------------
Date: Thu, 16 Oct 2003 17:11:01 +1000
From: Sisyphus <kalinaubears@iinet.net.au>
Subject: Re: PPM 'upgrade' command broken?
Message-Id: <3f8e453b$0$23608$5a62ac22@freenews.iinet.net.au>
James Willmore wrote:
> On Wed, 15 Oct 2003 21:53:32 GMT
> "Eric McDaniel" <NOSPAM@NOSPAM.COM> wrote:
>
>>Installation: Win32 ActivePerl 5.8.0.806
>
> <snip>
>
> Try going ActiveState's home page and looking under support. They
> have a knowledge base you can search - and submit bug reports if you
> can't find the answer to your question.
>
> HTH
>
I think AS also hosts a ppm-specific mailing list. Might be worth a shot.
Does the OP *need* to uninstall before doing an install ?
For me, 'ppm install ...' will install an update over the top. I've
found no need to first uninstall the outdated package.
But my ppm is quite old (version 2.1.4.0 - or something like that). It
has given me no trouble at all.
Cheers,
Rob
--
To reply by email u have to take out the u in kalinaubears.
------------------------------
Date: 16 Oct 2003 12:36:59 +0100
From: Brian McCauley <nobull@mail.com>
Subject: Re: Strange behaviour with '\r' character [[ sorry my other post was wrong typed ]]
Message-Id: <u94qy9tnvo.fsf@wcl-l.bham.ac.uk>
i5513@hotmail.com (i5513) writes:
> Hi!. I don't understand ...
Try this:
print "\\r is whitespace!\n" if "\r" =~ /^\s$/;
Now do you understand?
--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
------------------------------
Date: Wed, 15 Oct 2003 22:11:59 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: string substitution problem
Message-Id: <slrnbos33v.856.tadmc@magna.augustmail.com>
Jeff 'japhy' Pinyan <pinyaj@rpi.edu> wrote:
> You
> should either do
>
> system(...) and die "...";
>
> or
>
> system(...) == 0 or die "...";
or:
!system(...) or die "...";
Which is what I use, because I'm already used to
writing "somefunc() or die".
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: Thu, 16 Oct 2003 08:38:49 +0100 (BST)
From: "Dave Saville" <dave.nospam@ntlworld.com>
Subject: Re: string substitution problem
Message-Id: <qnirfnivyyragyjbeyqpbz.hmuogp0.pminews@text.news.ntlworld.com>
On Wed, 15 Oct 2003 14:12:49 -0700, Purl Gurl wrote:
>Mostly true. WinME is also in there. This problem with flock will
>appear anytime a "Win32 System" is used. This does not exclude
>WinNT5 completely. Possibly OS/2 exhibits this problem, not sure.
>Other candidates would be systems using DR-DOS or IBM DOS.
FYI flock() works on OS/2, at least with v5.8.0 - Some time ago I
tested with two scripts as I had the same problem - cgi updating a
common file. One script held an exclusive lock on a file and then
waited on keyboard input - the other tried to get the lock and said
when it did. The latter script just hung until I replied to the first
and it released the lock.
Regards
Dave Saville
NB switch saville for nospam in address
------------------------------
Date: 16 Oct 2003 10:08:06 GMT
From: anno4000@lublin.zrz.tu-berlin.de (Anno Siegel)
Subject: Re: string substitution problem
Message-Id: <bmlqm6$nvg$2@mamenchi.zrz.TU-Berlin.DE>
Purl Gurl <purlgurl@purlgurl.net> wrote in comp.lang.perl.misc:
> Jeff Pinyan wrote:
>
> > Purl Gurl wrote:
>
> > >system("perl -i.bak -e 's/gurlpurl/purlgurl/e' test.txt") or die "FUBAR $!";
>
> > > Use of a die causes a script to die at that line but does
> > > not generate any error message.
>
> > That's because system() returns false on success, not on failure. You
> > should either do
>
> No! Win32/DOS returns "success" and perl core reads this as "failure."
>
> Personally I consider this a perl core programming error for Perl
> versions ported for Win32.
So you want system() to return reversed logic on Win32, making it
non-portable? I don't think so.
Anno
------------------------------
Date: Thu, 16 Oct 2003 09:05:52 GMT
From: "Edward Wildgoose" <Ed+nospam@ewildgoose.demon.co.uk@>
Subject: Re: Threads and OO Question
Message-Id: <Qbtjb.6143767$mA4.874025@news.easynews.com>
> > I say this because the docs on threads::shared (have you looked at
> > threads::shared?) says that
> >
> > " bless is not supported on shared references. In the current version,
> > bless will only bless the thread local reference and the blessing will
> > not propagate to the other threads. This is expected to be implemented
> > in a future version of Perl."
Aha, some further research on this shows that the warning is just a warning.
Basically it means that you should bless after sharing, not before. It
doesn't seem to be a limitation on blessing objects, ie the sample code now
becomes:
package MyStats;
use threads::shared;
sub new {
my $class = shift;
my $this = { bytes_in => 0,
bytes_out => 0};
bless($this, $class);
share($this);
return $this;
}
Further interesting observations (on Activestate perl at least) are that now
"MyStats" is shared, if I then create a worker thread variable of type
MyStats in the scope of the worker thread package, this itself is
automatically shared even if I don't share it in the worker thread, ie I can
see it from the main thread.
I can't decide if this is expected or not to be honest? I need to test
locking now I suppose... Will it work properly with objects...?
There must be some good samples on this kind of stuff somewhere though?
Thanks all
Ed W
------------------------------
Date: Thu, 16 Oct 2003 12:27:55 -0000
From: Sean Keplinger <bhjp@spookyworld.dnsalias.com>
Subject: XML::Checker::Parser
Message-Id: <vot3mbe2o58a6c@corp.supernews.com>
I'm attempting to use XMl::Checker::Parser to validate an XML document with
two schemas. The problem I'm having is that only one schema is recognized. Code
snippet follows:
-----------------------------------------------------------------
use XML::Checker::Parser;
my %options = (KeepCDATA => 1,
Handlers => [Unparsed => \&handle_unparsed]);
my $xp = new XML::Checker::Parser (\%options);
my $xml_file = @ARGV[0];
eval {
local $XML::Checker::FAIL = \&handle_error;
$xp->parsefile($xml_file);
};
------------------------------------------------------------------
Could someone point me in the right direction? Do I need to use a different
validator, or is there some way to define multiple XSD's when I define the
parser?
Thanks,
Sean
--
\___/ Sean Keplinger
|o,o| skeplin at one dot net
\/ ) http://spookyworld.dnsalias.com
----mm-----------------------------------
------------------------------
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 5669
***************************************