[19981] in Perl-Users-Digest
Perl-Users Digest, Issue: 2176 Volume: 10
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Thu Nov 22 00:05:52 2001
Date: Wed, 21 Nov 2001 21:05:08 -0800 (PST)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Message-Id: <1006405507-v10-i2176@ruby.oce.orst.edu>
Content-Type: text
Perl-Users Digest Wed, 21 Nov 2001 Volume: 10 Number: 2176
Today's topics:
Re: CGI-Mysql question <havoc@harrisdev.com>
Re: Chat? <havoc@harrisdev.com>
Creating a Perl app. Help with installation? <mcnuttj@dnps-linux1.telecom.missouri.edu>
Re: Creating a Perl app. Help with installation? <mgjv@tradingpost.com.au>
Re: Creating a Perl app. Help with installation? <comdog@panix.com>
Re: File position of of every word in a file <krahnj@acm.org>
How can you do a safe unlink? <admin@asarian-host.net>
Re: How can you do a safe unlink? (Mark Jason Dominus)
Re: How can you do a safe unlink? <ilya@martynov.org>
Re: How can you do a safe unlink? <admin@asarian-host.net>
Re: How can you do a safe unlink? <ilya@martynov.org>
Re: How can you do a safe unlink? <ahamm@programmer.net>
Re: how to calculate the CRC of a string... <no_mto@hotmail.com>
Re: Script for stripping FONT (HTML) tags (Tad McClellan)
Re: Script for stripping FONT (HTML) tags (Randal L. Schwartz)
Re: Script for stripping FONT (HTML) tags <bart.lateur@skynet.be>
Re: SNMP:: Session, SNMP::Varbind (Garry Williams)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Wed, 21 Nov 2001 21:35:45 -0800
From: bigpig <havoc@harrisdev.com>
Subject: Re: CGI-Mysql question
Message-Id: <3bfc7fe7_3@corp-goliath.newsgroups.com>
Steve wrote:
> I am hoping someone on this group has some advice, if not, you may like to
I'll answer your questions Steve. It looks like a Perl question, and it
walks like a Perl question. The only thing left is wether or not I know a
Perl question when I see it.
Opening a db connection with a Perl script should be exactly like opening a
db session with the user front end (mysql -u username -p dbname). Would you
log out and back in after every query? No. I'd treat your Perl script the
same way -- plus it has some major advantages (connect/disconnect time not
withstanding) such as being able to ask for such things as LAST_INSERT_ID
to identify the last element inserted by session opened by THIS INSTANCE of
the script (even if hundreds of other instances are inserting at the same
time, your session id is still unique).
havoc
______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net
------------------------------
Date: Wed, 21 Nov 2001 21:39:06 -0800
From: bigpig <havoc@harrisdev.com>
Subject: Re: Chat?
Message-Id: <3bfc80b1_3@corp-goliath.newsgroups.com>
Wanadoo wrote:
> Hi!!!!!!
> I wonder if is possible to make chat using HTML and Perl. Do I have to
> know socket programming?? Where I can find more informations about this?
> I think Perl can also be good for that purpose as Java, right?
>
> Help nad thanks!
>
> M.
Being an avid Java Avoider (having that highly developed sense of laziness
Randall Schwartz so often talks about) I've cassually glanced about for the
same thing. Randall Schwartz, the wizard himself, is in fact currently
working on a frame-based Perl chat script. When last I was at his site,
there was no code available, but I expect we'll see it in some future
article. it's not as clean as a Java solution, but it also avoid the mess
you can get into with Java.
In the end it may not be a good solution, but I'm willing to give it a shot.
havoc
______________________________________________________________________________
Posted Via Binaries.net = SPEED+RETENTION+COMPLETION = http://www.binaries.net
------------------------------
Date: 22 Nov 2001 02:50:33 GMT
From: <mcnuttj@dnps-linux1.telecom.missouri.edu>
Subject: Creating a Perl app. Help with installation?
Message-Id: <9thp5p$6gp$1@dipsy.missouri.edu>
Hey all!
Well, after a lot of help off and on from people in this group, I have a
pretty viable application that's used by most of the people in my
group. It does what I want the way I want it to (except the new features
I haven't had time to code). Have I said thanks for the help? If not,
thanks!
I have another question. :-)
So far I have been installing various things in /usr/local/bin,
/usr/local/man, /usr/local/lib (lot of stuff here). It's all pretty
hard-coded and I need to clean it up a little. I've looked at the
approaches some other programmers have taken (none of which seem to be the
same), but I could use some explicit advice. Here's what I've got so far:
1) The application's name is jscan (I can name it after myself if I want
to! :-) ). I install all my modules in /usr/local/lib/jscan. I want to
move these into ${prefix}/site_perl/JScan and then do 'use
JScan::modulename' rather than 'use lib /usr/local/lib/jscan'.
Is the safest way to do this in the Makefile like this (see below)?
PREFIX = /usr
MODSDIR = $(PREFIX)/lib/perl5/site_perl/JScan
Or is there some other dir that MODSDIR should point to? If we assume
that the README tells the user to modify PREFIX, is the rest reasonable?
2) Man pages. A lot of programs just do:
PREFIX = /usr
MANDIR = $(PREFIX)/man/mann
However, others specifically put stuff in /usr/man/mann or
/usr/local/man/mann, I guess depending upon what the author felt
like. What's the preferred method? I'm inclined to use what I show above
and let the user add the new dir to his/her MANPATH if the files wind up
someplace weird.
3) MIBs. This is the hard one. Right not I include a *bunch* of MIB
files and store them in /usr/local/lib/jscan/mibs (with a bunch of
subdirs). Again, right now this is hard-coded in there, but I'd like to
somehow make this relative to PREFIX from the Makefile (perhaps
$(PREFIX)/JScan/mibs). What's the best way to accomplish this?
First thought: Start by making the directory where the MIBs are stored a
variable ($options{mibdir}) in the first place, then set that variable via
the environment, a config file, command-line option, or all three (with
some precedence). Then have the default installation location
$(PREFIX)/JScan/mibs and automatically create a config file for the user
that points there. If all else fails, have the script default to looking
in (default PREFIX)/JScan/mibs.
Opinions and suggestions are welcome. Just about anything is better than
all this hard-coded stuff I've got and I need to clean it up now while I
feel like it or it's just going to get worse. :-P
--J
------------------------------
Date: Thu, 22 Nov 2001 04:26:23 GMT
From: Martien Verbruggen <mgjv@tradingpost.com.au>
Subject: Re: Creating a Perl app. Help with installation?
Message-Id: <slrn9vovjg.meb.mgjv@verbruggen.comdyn.com.au>
On 22 Nov 2001 02:50:33 GMT,
<mcnuttj@dnps-linux1.telecom.missouri.edu> wrote:
>
> 1) The application's name is jscan (I can name it after myself if I want
> to! :-) ). I install all my modules in /usr/local/lib/jscan. I want to
> move these into ${prefix}/site_perl/JScan and then do 'use
> JScan::modulename' rather than 'use lib /usr/local/lib/jscan'.
>
> Is the safest way to do this in the Makefile like this (see below)?
You should probably have a look at writing a Makefile.PL, and using
ExtUtils::MakeMaker for this. It's exactly what it was made for.
Read the h2xs documentation, and use it to set up a skeleton directory
structure. Move your modules and applications into that structure,
modify MANIFEST, README and Makefile.PL, and away you go.
The ExtUtils::MakeMaker documentation can help you write a
Makefile.PL, but I've found it educational in the past to just look at
what people did with the Makefile.PL that comes with the various CPAN
packages.
> 3) MIBs. This is the hard one. Right not I include a *bunch* of MIB
> files and store them in /usr/local/lib/jscan/mibs (with a bunch of
> subdirs). Again, right now this is hard-coded in there, but I'd like to
> somehow make this relative to PREFIX from the Makefile (perhaps
> $(PREFIX)/JScan/mibs). What's the best way to accomplish this?
You'd probably have to write a bit of custome Makefile for this, but
again, MakeMaker can help you out here in determining the "best" place
to put things.
Martien
--
|
Martien Verbruggen | Little girls, like butterflies, need
Trading Post Australia Pty Ltd | no excuse - Lazarus Long
|
------------------------------
Date: Wed, 21 Nov 2001 22:43:26 -0600
From: brian d foy <comdog@panix.com>
Subject: Re: Creating a Perl app. Help with installation?
Message-Id: <comdog-07DBF9.22432621112001@news.panix.com>
In article <9thp5p$6gp$1@dipsy.missouri.edu>,
<mcnuttj@dnps-linux1.telecom.missouri.edu> wrote:
> 1) The application's name is jscan (I can name it after myself if I want
> to! :-) ). I install all my modules in /usr/local/lib/jscan. I want to
> move these into ${prefix}/site_perl/JScan and then do 'use
> JScan::modulename' rather than 'use lib /usr/local/lib/jscan'.
> Is the safest way to do this in the Makefile like this (see below)?
why not use ExtUtils::MakeMaker? start with h2xs, and most of
the magic is done for you by the Makefile.PL is creates for you.
> 2) Man pages. A lot of programs just do:
>
> PREFIX = /usr
> MANDIR = $(PREFIX)/man/mann
ExtUtils::MakeMaker handles this too.
> 3) MIBs. This is the hard one. Right not I include a *bunch* of MIB
> files and store them in /usr/local/lib/jscan/mibs (with a bunch of
> subdirs). Again, right now this is hard-coded in there, but I'd like to
> somehow make this relative to PREFIX from the Makefile (perhaps
> $(PREFIX)/JScan/mibs). What's the best way to accomplish this?
ExtUtils::MakeMaker can handle this too. you can add to the
Makefile that Makefile.PL produces with postamble(). See the
ExtUtils::MakeMaker man page for an example.
Here are some starting resources:
http://www.perldoc.com/perl5.6.1/bin/h2xs.html
http://www.perldoc.com/perl5.6.1/lib/ExtUtils/MakeMaker.html
--
brian d foy <comdog@panix.com> - Perl services for hire
CGI Meta FAQ - http://www.perl.org/CGI_MetaFAQ.html
Troubleshooting CGI scripts - http://www.perl.org/troubleshooting_CGI.html
------------------------------
Date: Thu, 22 Nov 2001 03:09:47 GMT
From: "John W. Krahn" <krahnj@acm.org>
Subject: Re: File position of of every word in a file
Message-Id: <3BFC6C7B.4F8D8610@acm.org>
Rob van Strien wrote:
>
> How can I get the file position of each single word in a file?
> I can read the file line by line and chop it up in words, but
> the tell-function will always return the file position of the
> (end of the) line I'm on, not the words.
Well it depends on how you define "words" but here is a simplistic
approach:
#!/usr/bin/perl -w
use strict;
use Fcntl ':seek';
my @index;
open IN, '< stats.txt' or die "Cannot open 'stats.txt': $!";
my $tell = tell IN;
while ( <IN> ) {
1 while /(\S+)/g and push @index, [ $-[0] + $tell, $+[0] - $-[0] ];
$tell = tell IN;
}
print "\nFound ", scalar @index, " words\n\n";
for my $index ( @index ) {
my $word;
seek IN, $index->[0], SEEK_SET;
read IN, $word, $index->[1];
print "$word\n";
}
close IN;
__END__
John
--
use Perl;
program
fulfillment
------------------------------
Date: Thu, 22 Nov 2001 00:42:22 GMT
From: "Mark" <admin@asarian-host.net>
Subject: How can you do a safe unlink?
Message-Id: <NRXK7.48414$qx2.3037316@bin5.nnrp.aus1.giganews.com>
How can you do a safe unlink?
This may seem like a trivial question, but, to my knowledge, there is no way
to safely delete a file in Perl! Say, I am opening an article for reading:
open (ARTICLE, '/var/spool/news/article.1');
flock (ARTICLE, 2);
seek (ARTICLE, 0, 0);
...
close (ARTICLE);
Works fine. But what if someone else tries to delete that file? A prog that
expires articles, for instance. How to go about that? Get a lock, you say?
Nope, that won't work. Because flocks are applied to handles, not directly
to files; which means you have to create a filehandle for it first, before
you can lock a file. So, this WON'T work:
open (ARTICLE, '/var/spool/news/article.1');
flock (ARTICLE, 2);
unlink ('/var/spool/news/article.1');
close (ARTICLE);
Do that, and you will find the file still very much present. Which basically
means there is no way to acquire a lock for a safe unlink!
Another problem with the Perl locking mechanism is, that Perl does not allow
you to first lock a file, after which you can open it for either read or
write, but that it first requires you to open it, and only then you can get
a lock. So, in this example:
open (ARTICLE, '/var/spool/news/article.1');
flock (ARTICLE, 2);
I have first opened the file for reading, and only then been able to acquire
a lock. So, even if I were to figure out a safe unlink somehow, since the
file is already opened for reading, subsequent reads after I acquired the
lock will now fail should the file have been "safely" unlinked in the
meantime (and with "safely" I mean: having used a cooperative flock). And
why? Because even if a safe unlink were to properly wait to get a lock, it
makes no difference: the file was already opened by another program for
read.
Ideally, you want this (pseudocode):
flock ('/var/spool/news/article.1', 2);
open (ARTICLE, '/var/spool/news/article.1');
That would be the proper order: first you get a lock, then you get to do
with the file whatever you want. Or, instead of actually having to do
something with the file first (like open for read/write,) you would want to
get a generic handle to the file; like (pseudocode):
giveh (ARTICLE, '/var/spool/news/article.1');
Which would give you nothing but a handle to the file, without actually
having to open it for read or write. Then you could say (pseudocode):
giveh (ARTICLE, '/var/spool/news/article.1');
flock (ARTICLE, 2);
open (ARTICLE, '/var/spool/news/article.1');
That would work perfectly.
The flock mechanism, the way it works now, works flawlessly for when you do
anything to the file but delete it! I can safely write:
open (ARTICLE, '/var/spool/news/article.1');
flock (ARTICLE, 2);
And this will work, just so long as there is still a file left to deal with
after I acquired the lock. The file may have been read in, written to, that
is all fine; but it cannot have been unlinked in the meantime.
So, anyone out there who has dealt with this problem before?
Much obliged,
- Mark
------------------------------
Date: Thu, 22 Nov 2001 01:19:40 GMT
From: mjd@plover.com (Mark Jason Dominus)
Subject: Re: How can you do a safe unlink?
Message-Id: <3bfc52ab.5e7a$338@news.op.net>
Keywords: Pyle, accreditation, revelatory, wintertime
In article <NRXK7.48414$qx2.3037316@bin5.nnrp.aus1.giganews.com>,
Mark <admin@asarian-host.net> wrote:
>This may seem like a trivial question, but, to my knowledge, there is no way
>to safely delete a file in Perl! Say, I am opening an article for reading:
There are two things I don't understand here.
One is what you mean by 'safe'. You never say what you think the
problem will be. You just say either 'it will not work' or 'it is
unsafe'.
The other problem is the phrase 'in Perl'. You appear to be
describing a generic problem that is independent of language.
All this makes me feel like I haven't gotten your point.
>open (ARTICLE, '/var/spool/news/article.1');
>flock (ARTICLE, 2);
>seek (ARTICLE, 0, 0);
>
>...
>close (ARTICLE);
>
>Works fine. But what if someone else tries to delete that file?
On Windows system, the delete operation will fail. On a Unix system,
the delete operation will succeed, and the file will be removed from
the file system, but its data will remain intact until the reading
process closes it.
What about this is a problem?
>So, this WON'T work:
>
>open (ARTICLE, '/var/spool/news/article.1');
>flock (ARTICLE, 2);
>unlink ('/var/spool/news/article.1');
>close (ARTICLE);
>
>Do that, and you will find the file still very much present.
I did not find what you said. The file vanished as soon as the
process did the 'unlink'. I wonder if you really ran this program.
>Another problem with the Perl locking mechanism is,
You are confused. Perl has no locking mechanism. flock() just invokes
the operating system's locking mechanism.
I think you need to study your operating system's documentation, run a
few of these sample programs a little bit, and take time to learn why
it was designed the way it was, before you get any more worked up.
>So, anyone out there who has dealt with this problem before?
You might also try posting an article that actually explains what the
problem is. Then someone could follow up and tell you how to solve it.
--
@P=split//,".URRUU\c8R";@d=split//,"\nrekcah xinU / lreP rehtona tsuJ";sub p{
@p{"r$p","u$p"}=(P,P);pipe"r$p","u$p";++$p;($q*=2)+=$f=!fork;map{$P=$P[$f^ord
($p{$_})&6];$p{$_}=/ ^$P/ix?$P:close$_}keys%p}p;p;p;p;p;map{$p{$_}=~/^[P.]/&&
close$_}%p;wait until$?;map{/^r/&&<$_>}%p;$_=$d[$q];sleep rand(2)if/\S/;print
------------------------------
Date: 22 Nov 2001 04:44:31 +0300
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: How can you do a safe unlink?
Message-Id: <874rnny3y8.fsf@abra.ru>
>>>>> On Thu, 22 Nov 2001 00:42:22 GMT, "Mark" <admin@asarian-host.net> said:
Mark> How can you do a safe unlink?
Mark> This may seem like a trivial question, but, to my knowledge,
Mark> there is no way to safely delete a file in Perl! Say, I am
Mark> opening an article for reading:
Mark> open (ARTICLE, '/var/spool/news/article.1');
Mark> flock (ARTICLE, 2);
Mark> seek (ARTICLE, 0, 0);
Mark> ...
Mark> close (ARTICLE);
Mark> Works fine. But what if someone else tries to delete that file?
Mark> A prog that expires articles, for instance. How to go about
Mark> that? Get a lock, you say? Nope, that won't work. Because
Mark> flocks are applied to handles, not directly to files; which
Mark> means you have to create a filehandle for it first, before you
Mark> can lock a file. So, this WON'T work:
Mark> [..skip..]
Actually it all depends on OS you are using. Do not say 'there is no
way to safely delete a file in Perl'. You should say 'there is no way
to safely delete a file in OS or on filesystem I use'.
I suspect you are talking about Unix-like OS. In that case there is no
problem with file deletion. 'unlink' on Unix removes reference on this
file on filesystem. If it was last reference on file than it becomes
imposible to open new filehanles for this file. But you can still use
already opened filehandle. OS reclaims disk space for file without
references only if there is no open filehandles for it.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Thu, 22 Nov 2001 02:07:30 GMT
From: "Mark" <admin@asarian-host.net>
Subject: Re: How can you do a safe unlink?
Message-Id: <C5ZK7.49098$qx2.3094784@bin5.nnrp.aus1.giganews.com>
"Mark Jason Dominus" <mjd@plover.com> wrote in message
news:3bfc52ab.5e7a$338@news.op.net...
> One is what you mean by 'safe'. You never say what you think the
> problem will be. You just say either 'it will not work' or 'it is
> unsafe'.
I think I pretty much outlined what I meant with "safe": using the flock
mechanism to read/write to files.
> The other problem is the phrase 'in Perl'. You appear to be
> describing a generic problem that is independent of language.
>
> All this makes me feel like I haven't gotten your point.
True enough.
> >open (ARTICLE, '/var/spool/news/article.1');
> >flock (ARTICLE, 2);
> >seek (ARTICLE, 0, 0);
> >
> >...
> >close (ARTICLE);
> >
> >Works fine. But what if someone else tries to delete that file?
>
> On Windows system, the delete operation will fail. On a Unix system,
> the delete operation will succeed, and the file will be removed from
> the file system, but its data will remain intact until the reading
> process closes it.
Not entirely accurate. For starters, there is no "windows". Win9x, for
instance, does not support flock (Or, I should say: ActivePerl did not
support flock for Win9x, presumably because Win9x has no locking mechanism.)
On WinXP, to my joy, this function is fully implemented. Furthermore, on XP
the data also remains available for read, even if unlinked in-between. And,
in XP, the unlink does not fail either.
> What about this is a problem?
Either that the file should no longer be available for reading, because I
unlinked it; or that the read will fail once the file is unlinked (whereas
the file was already "approved" open for reading.)
> >So, this WON'T work:
> >
> >open (ARTICLE, '/var/spool/news/article.1');
> >flock (ARTICLE, 2);
> >unlink ('/var/spool/news/article.1');
> >close (ARTICLE);
> >
> >Do that, and you will find the file still very much present.
>
> I did not find what you said. The file vanished as soon as the
> process did the 'unlink'. I wonder if you really ran this program.
You see, the problem you're not getting, is that the unlink works just fine,
except that the "close (ARTICLE)" will make the file reappear again, as if
it were never unlinked. You seem to be missing your own point: that data
remains available for read; hence, the "close (ARTICLE)" closes the file as
if it were never deleted! Therefore, the problem: you can get a flock for
the file before you unlink it; but close the handle used to open the file
(to get the lock) and the file reappears again!
You should assume, of course, that I tried this out before I mentioned the
problem. What you constantly fail to understand, is my point that requiring
a filehandle to lock, is not an action without consequence. That to get a
filehandle for lock, you must first open the file (say, for read), the
consequence of which being, that closing that filehandle results in the file
being committed to disk again, regardless of whether you unlinked it
in-between!
So, my point remains: the only way to get a flock, is to get a filehandle;
and getting a filehandle, in consequence, results in a "closure" of the file
when that filehandle is closed again; so that an unlink after the flock does
not have the desired effect of the file disappearing.
> You are confused. Perl has no locking mechanism; flock() just invokes
> the operating system's locking mechanism.
Semantics; that is like saying Perl has no "open" mechanism, but just uses
the OS "open" functions. I think the confusion is yours. Perl has a great
many functions whose low-level implementation may vary from OS to OS. But
"flock" is as much a Perl function as are "open" and "close" for instance.
> I think you need to study your operating system's documentation, run a
> few of these sample programs a little bit, and take time to learn why
> it was designed the way it was, before you get any more worked up.
And you should try and grasp the nature of the problem before you say there
is no problem. It works better that way.
- Mark
------------------------------
Date: 22 Nov 2001 05:28:15 +0300
From: Ilya Martynov <ilya@martynov.org>
Subject: Re: How can you do a safe unlink?
Message-Id: <87r8qrwncw.fsf@abra.ru>
>>>>> On Thu, 22 Nov 2001 02:07:30 GMT, "Mark" <admin@asarian-host.net> said:
Mark> I think I pretty much outlined what I meant with "safe": using the flock
Mark> mechanism to read/write to files.
Note: flock have nothing to do with unlink in Unix-like OSes.
>> I did not find what you said. The file vanished as soon as the
>> process did the 'unlink'. I wonder if you really ran this program.
Mark> You see, the problem you're not getting, is that the unlink
Mark> works just fine, except that the "close (ARTICLE)" will make the
Mark> file reappear again, as if it were never unlinked. You seem to
Mark> be missing your own point: that data remains available for read;
Mark> hence, the "close (ARTICLE)" closes the file as if it were never
Mark> deleted! Therefore, the problem: you can get a flock for the
Mark> file before you unlink it; but close the handle used to open the
Mark> file (to get the lock) and the file reappears again!
File will not reappear again. Unlink deletes reference on file on
filesystem. Once filehandle is closed there is no references on file
on filesystem. At least I'm sure it will not reappear neither on
**BSD, nor Linux.
--
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
| Ilya Martynov (http://martynov.org/) TIV.net (http://tiv.net/) |
| GnuPG 1024D/323BDEE6 D7F7 561E 4C1D 8A15 8E80 E4AE BE1A 53EB 323B DEE6 |
-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
------------------------------
Date: Thu, 22 Nov 2001 15:20:19 +1100
From: "Andrew Hamm" <ahamm@programmer.net>
Subject: Re: How can you do a safe unlink?
Message-Id: <3bfc7da7_1@news.iprimus.com.au>
Ilya Martynov wrote in message <87r8qrwncw.fsf@abra.ru>...
>>>>>> On Thu, 22 Nov 2001 02:07:30 GMT, "Mark" <admin@asarian-host.net>
said:
>
>Mark> I think I pretty much outlined what I meant with "safe": using the
flock
>Mark> mechanism to read/write to files.
>
>Note: flock have nothing to do with unlink in Unix-like OSes.
>
>>> I did not find what you said. The file vanished as soon as the
>>> process did the 'unlink'. I wonder if you really ran this program.
>
>Mark> You see, the problem you're not getting, is that the unlink
>Mark> works just fine, except that the "close (ARTICLE)" will make the
>Mark> file reappear again, as if it were never unlinked. You seem to
>Mark> be missing your own point: that data remains available for read;
>Mark> hence, the "close (ARTICLE)" closes the file as if it were never
>Mark> deleted! Therefore, the problem: you can get a flock for the
>Mark> file before you unlink it; but close the handle used to open the
>Mark> file (to get the lock) and the file reappears again!
>
>File will not reappear again. Unlink deletes reference on file on
>filesystem. Once filehandle is closed there is no references on file
>on filesystem. At least I'm sure it will not reappear neither on
>**BSD, nor Linux.
>
On all UNIX that is the case. UNIX keeps track of reference counts to the
contents of the file. One reference count is the directory entry for the
file. On UNIX, a file may have multiple links from directories, therefore
even an unopened file can have a reference count >= 1.
UNIX also "adds one" for each open file handle to the file. Therefore a file
referenced by a single directory plus having one open handle will have a
reference count of 2.
If the directory entry is unlinked, then the reference count will drop to 1.
NOTE: if there was another directory entry referring to the file, it will
drop from say 3 to 2. These extra links are created on UNIX using the ln
command, which basically calls the link() system call. (Don't confuse
traditional hard links with symbolic links)
Anyway, since we still have an open file handle for the file, it is not
deleted. When that open file handle is closed, THEN the file deleted. If you
study this explanation, you'll be able to figure out why the UNIX (and Perl)
function is called unlink() instead of delete().
Hence, on UNIX, deleting an open file causes no problems for any process
currently accessing the file. This does not hold true for programs which
repeatedly open and close the same file, but that's considered a bad
programming technique anyway. Pointless really for an ordinary file.
On MS-DOS and Windows variants, they have a different concept of open files
and locking. A "standard" windows open() of a file causes a kind of lock to
be placed on the file which prevents it from being deleted. There are
fancier variations on the open() function in MS* which allow you to have
more control over the subject. It's so long since I did lowlevel programming
on MS* that I forget completely whether it's possible to setup to emulate
the UNIX method. I'm not sure if the NT kernel and variations have
approached UNIX's reference counting technique.
So whether it's UNIX or MS* you'll be sure that a process won't have a file
ripped out from underneath it. AND, any process that attempts to unlink a
file will get an error status from the unlink call on both platforms, so
good programmers of course check for that error status. I cannot comment
about MACOS or VMS or other platforms... no experience there.
Summary: I don't think there's anything unsafe about unlinking files as long
as you check for error results as necessary. There should be no need for
aquiring a flock on a file which you will be reading like a newsreader. Is
that your actual situation or it is just an illustration? I've looked at
your original message and I can't agree that the file would still be there.
Perhaps you have permission problems or something. I notice that you are not
checking for error results from any of the system calls.
--
Space Corps Directive #723
Terraformers are expressly forbidden from recreating Swindon.
-- Red Dwarf
------------------------------
Date: Thu, 22 Nov 2001 00:45:38 +0100
From: "MAGiC MANiAC^mTo" <no_mto@hotmail.com>
Subject: Re: how to calculate the CRC of a string...
Message-Id: <9thel3$8r5$1@news.kabelfoon.nl>
Hi Bart!
Perfect, It works fine now, many many thanks!!!
I've download it from Activestate perl. this works very nice!!...
I didn't know that...
Last but not least :
I like to upload it to my host when I'm ready with my script file.
What files do I have to upload to my host?...
Greetz Bart!
René
"Bart Lateur" <bart.lateur@skynet.be> schreef in bericht
news:80tnvt4lj6tdgrtfs2p7rr3fn10m15gq7t@4ax.com...
> MAGiC MANiAC^mTo wrote:
>
> >I research my perl directory's to find out how I can get start with
> >a crc string calculation. But I can't find out where to start, because
> >theres no information in my perl that has the words: string::crc or
> >string::crc32
> >do you have a suggestion where I can find how to startup a crc string
> >calculation?
>
> You'll have to get the modules first. What perl installation do you
> have? If your computer has a direct internet connection, it can fetch
> the modules by itself, before installing them. On Activestate perl, use
> the PPM utility. Just type "PPM" in a DOS window, and then you can do:
>
> install String::CRC
>
> at the command line.
>
> On Unix, the CPAN module can do pretty much the same.
>
> You can always download the modules yourself, and then do an install
> from the local files.
>
> --
> Bart.
------------------------------
Date: Wed, 21 Nov 2001 23:21:08 GMT
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Script for stripping FONT (HTML) tags
Message-Id: <slrn9vob6g.otp.tadmc@tadmc26.august.net>
Tad McClellan <tadmc@augustmail.com> wrote:
>Steve Holland <holland@origo.ifa.au.dk> wrote:
>
>> s/\<FONT\>//;
> ^ ^
> ^ ^
>> s/\<\/FONT>//;
> ^
> ^
>> s/\<FONT SIZE=\"\+1\"\>//;
> ^ ^ ^ ^ ^
> ^ ^ ^ ^ ^
>
>Please don't waste precious natural resources like that.
>
>None of those 8 backslashes can now be used in places where
>a backslash is actually required.
Errr, 2 serve a purpose. Only 7 do nothing. Sorry.
--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas
------------------------------
Date: 21 Nov 2001 15:57:55 -0800
From: merlyn@stonehenge.com (Randal L. Schwartz)
Subject: Re: Script for stripping FONT (HTML) tags
Message-Id: <m1vgg3smm4.fsf@halfdome.holdit.com>
>>>>> "Sasa" == Sasa Janiska <ggd@gaura.nitai.hr> writes:
Sasa> Hi!
Sasa> I'm pretty newbie in the Perl and soem concrete task is ahead of me which
Sasa> has to be finished asap.
Sasa> Please, do you know for any script which can strip <FONT>, </FONT> and
Sasa> <FONT SIZE="+1"> tags from the html files.
Sasa> I have a bunch of html files placed in several subfolders under root
Sasa> folder which has to be stripped of FONT tags since they have to be
Sasa> formatted via CSS.
Not thoroghly tested, but I usually get these things right on the
first try...
use HTML::Parser;
HTML::Parser->new(
default_h => [sub { print $_[0] }, "text"],
start_h => [sub { print $_[1] if $_[0] ne "font" }, "tagname, text"],
end_h => [sub { print $_[1] if $_[0] ne "font" }, "tagname, text"],
)->parse_file(\*DATA) || die $!;
__END__
<a>foo</a>
<font size="+3">bar</font>
--
Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
<merlyn@stonehenge.com> <URL:http://www.stonehenge.com/merlyn/>
Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
------------------------------
Date: Thu, 22 Nov 2001 00:16:06 GMT
From: Bart Lateur <bart.lateur@skynet.be>
Subject: Re: Script for stripping FONT (HTML) tags
Message-Id: <1ngovtgegptat2p7hcdrqur3stk697f1cn@4ax.com>
Sasa Janiska wrote:
>I have a bunch of html files placed in several subfolders under root
>folder which has to be stripped of FONT tags since they have to be
>formatted via CSS.
Then look out for HTML Tidy. It can do the conversion from this kind of
HTML file into one that uses CSS. It still contains a few bugs, but it's
useful. There's a free HTML editor with support for this tool: HTML-Kit,
see <http://www.chami.com/html-kit/>, with an included preview
"browser". You can see if the converted file still "works". Er, sorry,
no Perl content there. :-)
--
Bart.
------------------------------
Date: Thu, 22 Nov 2001 02:37:20 GMT
From: garry@ifr.zvolve.net (Garry Williams)
Subject: Re: SNMP:: Session, SNMP::Varbind
Message-Id: <slrn9vop75.7un.garry@zfw.zvolve.net>
On 21 Nov 2001 10:45:32 -0800, Anand Ramamurthy
<anand_ramamurthy@yahoo.com> wrote:
> I am trying to run the following script (an example I found
> on comp.lang.perl.misc:
When developing Perl applications, it is really, REALLY important to
enable warnings and to use strict.
#!/usr/bin/perl -w
use strict;
> use SNMP 1.8;
This asks for at least the 1.8 version of the SNMP module. Below you
indicate that the check failed, so I suspect that you have a very old
version of SNMP.pm . If not, just remove the version check. I think
you're out of date though, because I ran this without the error you
report.
> my $host = shift || localhost;
> my $comm = shift || public;
If you had "use strict;" in your program, these statements would
produce fatal errors at compile time. That's because you are using
bare words instead of string literals.
my $host = shift || 'localhost';
my $comm = shift || 'public';
You want a string assigned to these variables, so use a string to get
it done.
> $sess = new SNMP::Session(DestHost => $host, Community => $comm);
>
> $var = new SNMP::Varbind([]);
>
> do {
> $val = $sess->getnext($var);
> print "$var->[$SNMP::Varbind::tag_f].$var->[$SNMP::Varbind::iid_f]
> = ",
> "$var->[$SNMP::Varbind::val_f]\n";
> } until ($sess->{ErrorStr});
>
>
> I downloaded Net-SNMP-4.0.0.tar.gz from CPAN and installed SNMP.
This is not the SNMP module, but rather the Net::SNMP module. Your
program wants the SNMP module. You installed Net::SNMP from that tar
file. Here's my version of the SNMP module that compiles fine with
your code:
$ perl -MSNMP -le'print $SNMP::VERSION'
3.1.0
$
> 1. I get the error:
> SNMP does not define $SNMP::VERSION- version check failed .....
You apparently *do* have SNMP installed, but it is not the correct
version. Here's what I found on CPAN:
$ perl -MCPAN -eshell
cpan shell -- CPAN exploration and modules installation (v1.59_54)
ReadLine support enabled
cpan> i /SNMP/
CPAN: Storable loaded ok
Going to read /tmp/Metadata
Database was generated on Wed, 21 Nov 2001 07:20:58 GMT
...
Module SNMP (G/GS/GSM/SNMP-4.2.0.tar.gz)
...
cpan> q
$
Install this version or the one I have installed (3.1.0). But since
your version is out of date, you probably need a new version of
libsnmp, too. Check out sourceforge.com to get the latest. It
includes the Perl module SNMP.
> If I change use SNMP 1.8; to use Net::SNMP
> I get following error:
> Can't locate object method "new" via package "SNMP:Session" (perhaps
> you forgot to load "SNMP::Session").
Change it to
use SNMP;
But I bet you still have problems because you seem to have an out of
date version of libsnmp *and* SNMP.pm .
> Am I missing anything from the Net::SNMP installation i
Wrong module. The question is not relevant.
> or
> something wrong withe script.
Only the stuff I mentioned, but even so, it will compile with the
correct version of SNMP. But please enable warnings and use strict in
Perl programs.
> All I am doing in my script is to do a snmpwalk to make sure that
> I can reach the device (an alternate to ping).
>
> Thank you
Hope this helps.
--
Garry Williams
------------------------------
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 2176
***************************************