[23480] in Perl-Users-Digest

home help back first fref pref prev next nref lref last post

Perl-Users Digest, Issue: 5693 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Wed Oct 22 03:06:11 2003

Date: Wed, 22 Oct 2003 00:05:10 -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           Wed, 22 Oct 2003     Volume: 10 Number: 5693

Today's topics:
    Re: -w <nobody@dev.null>
    Re: DBI & primary keys <REMOVEsdnCAPS@comcast.net>
        First Perl/CGI need critique on current code before fur <kazack@talon.net>
    Re: First Perl/CGI need critique on current code before <REMOVEsdnCAPS@comcast.net>
    Re: First Perl/CGI need critique on current code before (Tad McClellan)
    Re: First Perl/CGI need critique on current code before (Tad McClellan)
        Further on Taint - exact code that has the problem (Ben)
    Re: Further on Taint - exact code that has the problem <wwonko@rdwarf.com>
    Re: Help me with is code <tom@nosleep.net>
    Re: Installing DBD::Sybase on MAC (Vijoy Varghese)
    Re: Kill forked process on Windows 2000 (sandor)
    Re: Perl on AS400 (Michel)
    Re: Regular expressions when searching for string conta <jhalbrook@bjc.org>
    Re: Regular expressions when searching for string conta (Tad McClellan)
        Stale data in DB_File? <admin@asarian-host.net>
    Re: Stale data in DB_File? <invalid-email@rochester.rr.com>
    Re: Taint - having some real trouble here, taint/perl e (Tad McClellan)
        Taint differences between 5.8.0 and 5.8.1? <mb@uq.net.au>
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

----------------------------------------------------------------------

Date: Wed, 22 Oct 2003 01:25:39 GMT
From: Andras Malatinszky <nobody@dev.null>
Subject: Re: -w
Message-Id: <3f95dc91$1@bandit2.georgetown.edu>



Brad Baxter wrote:
> One of Abigail's signature lines:
> 
> perl -swleprint -- -_=Just\ another\ Perl\ Hacker
> 
> This one I actually got.  Except for the '-w' part.  Does -w serve a
> specific function in this case over and above its usual one?  Just a case
> of an inquiring mind ...
> 
> Regards,
> 
> Brad

Swleprint is a lot more mellifluous than sleprint...



------------------------------

Date: Tue, 21 Oct 2003 20:15:09 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: DBI & primary keys
Message-Id: <Xns941BD835EC60Bsdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"Bigus" <someone@somewhere.com> wrote in
news:bn2rec$r4e@newton.cc.rl.ac.uk: 

> I'm inserting a new record into a MySQL table using Perl DBI. I need
> to retrieve the unique primary key that's created automatically by the
> db as the new record is inserted. Since this will be a multi-user
> application, and two different users could be creating new records in
> that db within a split-second of each other, I'm not sure whether
> performing a subsequent SELECT statement to find out the max number in
> that column will be water-tight enough. I would have thought it must
> be a fairly common desire to want to know the primary key for a newly
> inserted record, but can't find any mention of it in the DBI
> instructions. Any ideas? 

MySQL provides a built-in function to achieve this: LAST_INSERT_ID.  See 
http://www.mysql.com/doc/en/Miscellaneous_functions.html#IDX1412

The server maintains this value on a per-connection basis, so you simply do 
not have to worry about other concurrent inserts on the table.

Yay MySQL.  :-)

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP5XaFmPeouIeTNHoEQIc9QCcCR3FxynfHYmXQ9iJ/doymg5o4/0AmwUZ
2QCGubO5Dtq0G4cH/MXjo309
=Qyvg
-----END PGP SIGNATURE-----


------------------------------

Date: Wed, 22 Oct 2003 00:53:30 GMT
From: "kazack" <kazack@talon.net>
Subject: First Perl/CGI need critique on current code before further developement
Message-Id: <eyklb.5727$Bv6.1775291@news1.epix.net>

This is part of an elaborate web counter that I am in the process of
writing.  I am hoping that once I am done with this little project I will be
able to move on to something else.  I was told that this is a waste of time
and why am I trying to re-invent the wheel, but by re inventing the wheel
you learn alot.  I have been modifying perl/cgi scripts for about a year and
now am in the process of actually trying to write one that works.  I am not
familiar with what is good and bad habits when it comes to Perl/CGI so I am
hoping that someone can critique this and let me know how I can make this
code even better!!!

Thank you,
Shawn Mulligan

#!/usr/bin/perl
use CGI::Carp qw(fatalsToBrowser);
my ($date_num, $month) = (localtime $time)[3,4];
$month ++;
my $ipfile = sprintf '%02d%02d.vipd', ++$month, $date_num;
($slash, $document) = split(//, $ENV{'DOCUMENT_URI'});
 if ($slash eq "/") { $ThisPage = $ENV{'DOCUMENT_URI'}; }
 else { $ThisPage = "/$ENV{'DOCUMENT_URI'}"; }
  if(-e $ipfile){
 open(ip, "+<$ipfile") || die ("Can't open $ipfile\n");
 }
 else
 {
 open(ip, "+>>$ipfile") || die ("Can't open $ipfile\n");
 }

 while (<ip>) {
  chop;
  ($ip, $file) = split(/::/, $_);
  $ip{$file} = $ip;}
  $ip{$ThisPage}++;
  seek(ip, 0, 0);
  foreach $file (keys %ip) { print ip $ip{$file}, "::", $file, "\n";
  }
 close(ip);
}





------------------------------

Date: Tue, 21 Oct 2003 21:53:27 -0500
From: "Eric J. Roode" <REMOVEsdnCAPS@comcast.net>
Subject: Re: First Perl/CGI need critique on current code before further developement
Message-Id: <Xns941BE8E06152Asdn.comcast@216.196.97.136>

-----BEGIN xxx SIGNED MESSAGE-----
Hash: SHA1

"kazack" <kazack@talon.net> wrote in
news:eyklb.5727$Bv6.1775291@news1.epix.net: 

> I was told that this is a
> waste of time and why am I trying to re-invent the wheel, but by re
> inventing the wheel you learn alot.

I completely agree.  Good for you.

> I have been modifying perl/cgi
> scripts for about a year and now am in the process of actually trying
> to write one that works.  I am not familiar with what is good and bad
> habits when it comes to Perl/CGI so I am hoping that someone can
> critique this and let me know how I can make this code even better!!!

Glad to help.  I've been writing Perl CGI scripts for a living for seven 
years now.  I hope my insight will be valuable to you.


> #!/usr/bin/perl

For CGI scripts, in general, you want to add "-T" to the above command-
line.  Not necessary, but it catches some potential security errors.

Also, before any other code, I would strongly recomment you add:

    use strict;

This will catch a lot of coding errors.

> use CGI::Carp qw(fatalsToBrowser);
> my ($date_num, $month) = (localtime $time)[3,4];
> $month ++;
> my $ipfile = sprintf '%02d%02d.vipd', ++$month, $date_num;

I'm going to assume that you know that the month doesn't need to be 
incremented twice, and that the fact you did so above is a simple typo or 
lapse of attention.


> ($slash, $document) = split(//, $ENV{'DOCUMENT_URI'});

Use 'my'.

You're looking at the first two characters of DOCUMENT_URI?  Is that right?  
Sounds fishy.

>  if ($slash eq "/") { $ThisPage = $ENV{'DOCUMENT_URI'}; }
>  else { $ThisPage = "/$ENV{'DOCUMENT_URI'}"; }

Ah, you're really only looking at the first character.  Ditch $document.  
Better yet, replace the above three lines with something like

    $ThisPage = $ENV{DOCUMENT_URI};
    $ThisPage = "/$ThisPage" unless $ThisPage =~ /^\//;

Or, since typing $ThisPage gets tedious, a useful idiom is:

    $ThisPage = $ENV{DOCUMENT_URI};
    for ($ThisPage) { $_ = "/$_" unless /^\// }

>   if(-e $ipfile){
>  open(ip, "+<$ipfile") || die ("Can't open $ipfile\n");
>  }
>  else
>  {
>  open(ip, "+>>$ipfile") || die ("Can't open $ipfile\n");
>  }

If the file doesn't exist, you want to append to it?

ALWAYS include $! in your file open error messages -- otherwise, you'll 
just be guessing as to WHY the file couldn't be opened.

Also, I would suggest varying the error messages, so you know which 
statement (the "then" or the "else") generated the error.

>  while (<ip>) {
>   chop;

Use "chomp", not "chop".

>   ($ip, $file) = split(/::/, $_);
>   $ip{$file} = $ip;}

Is the } a typo?

You never declared %ip in a 'my' statement.

>   $ip{$ThisPage}++;
>   seek(ip, 0, 0);
>   foreach $file (keys %ip) { print ip $ip{$file}, "::", $file, "\n";
>   }
>  close(ip);

Wait -- you're closing the file while looping over it?

> }

It looks like if the file doesn't exist when the program is run, nothing 
ever gets written to it.  Is that correct?

- -- 
Eric
$_ = reverse sort $ /. r , qw p ekca lre uJ reh
ts p , map $ _. $ " , qw e p h tona e and print

-----BEGIN xxx SIGNATURE-----
Version: PGPfreeware 7.0.3 for non-commercial use <http://www.pgp.com>

iQA/AwUBP5XxImPeouIeTNHoEQIkNACfcO1gRRlR6nC9S8aOaQ8pgFZPulMAnjhi
1XbisoPxvf+n0O6h2qmvwUNW
=wR8e
-----END PGP SIGNATURE-----


------------------------------

Date: Tue, 21 Oct 2003 22:20:26 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: First Perl/CGI need critique on current code before further developement
Message-Id: <slrnbpbtrq.2du.tadmc@magna.augustmail.com>

Eric J. Roode <REMOVEsdnCAPS@comcast.net> wrote:
> "kazack" <kazack@talon.net> wrote in
> news:eyklb.5727$Bv6.1775291@news1.epix.net: 


>>   if(-e $ipfile){
>>  open(ip, "+<$ipfile") || die ("Can't open $ipfile\n");
>>  }
>>  else
>>  {
>>  open(ip, "+>>$ipfile") || die ("Can't open $ipfile\n");
>>  }

[snip]

> Also, I would suggest varying the error messages, so you know which 
> statement (the "then" or the "else") generated the error.


Or simply leave off the \n in die()'s argument and let perl tell
you which one it was.


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Tue, 21 Oct 2003 22:32:55 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: First Perl/CGI need critique on current code before further developement
Message-Id: <slrnbpbuj7.2du.tadmc@magna.augustmail.com>

kazack <kazack@talon.net> wrote:

> hoping that someone can critique this and let me know how I can make this
> code even better!!!

> #!/usr/bin/perl


Enable taint checking:

   #!/usr/bin/perl -T

Enable warnings:

   use warnings;

Enable strictures:

   use strict;


> ($slash, $document) = split(//, $ENV{'DOCUMENT_URI'});


This probably does not do what you think it does, judging by
your choice of variable name.

Did you mean to give split() a 3rd argument?


>  if ($slash eq "/") { $ThisPage = $ENV{'DOCUMENT_URI'}; }
>  else { $ThisPage = "/$ENV{'DOCUMENT_URI'}"; }


You can replace the 3 lines above with:

   my $ThisPage = $ENV{'DOCUMENT_URI'};
   $ThisPage =~ s#^([^/])#/$1#;        # or   s#^(?!/)#/#;


>  open(ip, "+>>$ipfile") || die ("Can't open $ipfile\n");


Your code will suddenly stop working when you upgrade to a new
Perl version that introduces a new function named ip().

Use UPPER CASE filehandles to guard against that.


>   seek(ip, 0, 0);


What if the seek() fails?

You don't always get what you asked for, so it is best to check:

   seek(IP, 0, 0) or die "could not seek to start of file  $!";


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: 21 Oct 2003 15:55:33 -0700
From: 2stormts@nemontel.net (Ben)
Subject: Further on Taint - exact code that has the problem
Message-Id: <5c8f38ff.0310211455.6a9e6f72@posting.google.com>

This is a followup to my earlier post, sorry it's not in the same
thread, but it's been several hours and google still hasn't coughed up
the first post, so I can't get it into the same thread.

 $cmd = "pogmaker";
 $command = "$cmd $part $befo $fute $cols $redd >output.txt &";
 $command =~ /(.*)/;
 $command = $1;
 $ENV{"PATH"}="/bin:/usr/bin";
 delete @ENV{'IFS','CDPATH','ENV','BASH_ENV'};
 # print "Taint checks seem to be on<br>"
 # unless eval { local $^W; unlink "$^X$^T"; 1 };
 $rez = system($command);

FYI, the print "Taint.... does not indicate that taint is on by
printing.

pogmaker is in /usr/bin, has execute permission for anyone, owned by
root.

pogmaker absolutely will not run.

Ben


------------------------------

Date: Tue, 21 Oct 2003 23:30:56 +0000 (UTC)
From: Louis Erickson <wwonko@rdwarf.com>
Subject: Re: Further on Taint - exact code that has the problem
Message-Id: <bn4fjg$6t8$1@holly.rdwarf.com>

Ben <2stormts@nemontel.net> wrote:
:  $cmd = "pogmaker";
:  $command = "$cmd $part $befo $fute $cols $redd >output.txt &";
:  $command =~ /(.*)/;
:  $command = $1;
:  $ENV{"PATH"}="/bin:/usr/bin";
:  delete @ENV{'IFS','CDPATH','ENV','BASH_ENV'};
:  # print "Taint checks seem to be on<br>"
:  # unless eval { local $^W; unlink "$^X$^T"; 1 };
:  $rez = system($command);

: FYI, the print "Taint.... does not indicate that taint is on by
: printing.

Then I suspect taint is not on.  Why do you think taint is on?

: pogmaker is in /usr/bin, has execute permission for anyone, owned by
: root.

: pogmaker absolutely will not run.

Why not?  Have you checked the return values from system?  See
perldoc -f system to get how to decode the error values from
system to make sure it's working, and check your server logs for
any messages to stderr indicating possible problems from
your program itself.

-- 
Louis Erickson - wwonko@rdwarf.com - http://www.rdwarf.com/~wwonko/

"I don't think so," said Rene Descartes.  Just then, he vanished.


------------------------------

Date: Tue, 21 Oct 2003 21:40:10 -0700
From: "Tom" <tom@nosleep.net>
Subject: Re: Help me with is code
Message-Id: <3f960964$1@nntp0.pdx.net>

> SpamAssassin costs $0/year.
>
and runs on Windows?
Granted, I run several Linux boxes, but I don't use them for email for a
number of reasons.




------------------------------

Date: 21 Oct 2003 22:10:05 -0700
From: viijv@thedifferenZ.com (Vijoy Varghese)
Subject: Re: Installing DBD::Sybase on MAC
Message-Id: <4c08aaff.0310212110.2ea0f4b1@posting.google.com>

Thank you Michael
Hehehe, the only reply I got was from the 'author of DBD::Sybase'? I
am excited...

A few questions...


"Michael Peppler" <mpeppler@peppler.org> wrote in message 

> First, Sybase's OpenClient package doesn't work with MS-SQL 7.x or 2K.
> Second, how could the *linux* version of OpenClient ever work on your
> MacOSX box??? The underlying architecture is completely different!

What about installing 'Free BSD Intel' from
http://linux.sybase.com/ase/11033download.html.
Will this work on a Mac osX and DBD::Sybase?
If it does, should I install both files to get it work with
DBD::Sybase?

sybase-ocsd-10.0.4-FreeBSD-6.i386.tgz AND
sybase-ase-11.0.3.3-FreeBSD-6.i386.tgz

> Anyway - you should look at FreeTDS (http://www.freetds.org/) for a
> library that will allow you to access MS-SQL from your MacOSX box.
At the same time, I am trying to install freetds on Mac, but some
complications with libtool and Mac, anyways I am getting good support
from freetds mailing-group
[http://lists.ibiblio.org/pipermail/freetds/2003q4/014109.html], so
hoping to solve my problems soon.

Regards
Vijoy~


------------------------------

Date: 21 Oct 2003 22:55:27 -0700
From: sandorpatocs@netscape.net (sandor)
Subject: Re: Kill forked process on Windows 2000
Message-Id: <e52b0bd5.0310212155.76cd61b3@posting.google.com>

Bart Lateur <bart.lateur@pandora.be> wrote in message news:<fdr0pv8hldblon6md885ca96a33da6rif9@4ax.com>...
> Stéphane Métais wrote:
> 
> >So my question : does the "kill" command works properly on Windows 2000 
> >? If yes, how ?
> 
> Maybe it does, maybe it doesn't, but AFAIK, fork() is emulated, using
> threads. In short: (I think) the parent and the child are actually
> threads in the same process. That could be the cause of your problems.
> 
> Using Win32::Process, you can really launch a separate program for the
> child. See this node on Perlmonks for a starting point. Good luck.
> 
> 	<http://perlmonks.org/?node_id=192421>

 ... or use Proc::Background for a really separate process that is portable
to unix and win32


------------------------------

Date: 21 Oct 2003 23:43:02 -0700
From: mbr@petercam.be (Michel)
Subject: Re: Perl on AS400
Message-Id: <c8f5d58b.0310212243.1b1886ac@posting.google.com>

halbrook@keitzer.com (Joe Halbrook) wrote in message news:<3268a75d.0310211214.12d00ca3@posting.google.com>...
> I'd love to know what is required to install Perl (and Perl
> modules) on an AS400.  I know you have to manipulate the HTTP Server,
> as well.  I've used Perl on UNIX/Linux, but not on the AS400. I've 
> been developing on the AS400 (in RPG) since it hit the market.
> 
> Joe Halbrook

Hi Joe,

Have a look at: 
http://www.redbooks.ibm.com/tstudio/workshop/tiptools/perl.htm
From there you will have all the information needed.
And please don't  miss the Readme ;-)

Michel


------------------------------

Date: Tue, 21 Oct 2003 17:43:05 -0500
From: "JK" <jhalbrook@bjc.org>
Subject: Re: Regular expressions when searching for string containing brackets or parans ..
Message-Id: <vpbdjoll6jrj84@corp.supernews.com>

Thanks so much, Tedd.

Will this work even if $searchstring contains an "reserved"
character, or should I:

$newsearchstring =~ /\Q$searchstring\E/i)
if ($newsearchstring =~ /\Q$_\E/i) {
 ...

Sorry for the newbie questions.  :-)

Joe Halbrook


>>>>

"Tedd Hansen" <news@tedd.konge.net> wrote in message
news:3f958c52$1@news.broadpark.no...
>
> From the manual;
> if ($searchstring =~ /\Q$_\E/i) {
>
>
> it quotes the string correctly before processing the regex
>
> - Tedd
>
> "Joe Halbrook" <halbrook@keitzer.com> wrote in message
> news:3268a75d.0310211051.7ba600a0@posting.google.com...
> > I am trying to search a string that may contain brackets or parenthesis.
> > Could someone suggest a way to do this such that the seacrh will not
> > fail, when the string search does contain the special character, i.e.
> >
> > if ($searchstring =~ /$_/i) {
> >
> >   when $searchstring and $_ may contain a string with a [, ], (, or )
> character?
> >
> > Much thanks, in advance.
> >
> > Joe Halbrook
>
>




------------------------------

Date: Tue, 21 Oct 2003 19:27:31 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Regular expressions when searching for string containing brackets or parans ..
Message-Id: <slrnbpbjnj.22h.tadmc@magna.augustmail.com>


[ please do not top-post. Text rearranged. ]


JK <jhalbrook@bjc.org> wrote:
> "Tedd Hansen" <news@tedd.konge.net> wrote in message
> news:3f958c52$1@news.broadpark.no...
>>
>> From the manual;


That's the "Quote and Quote-like Operators" section of the perlop manual.


>> if ($searchstring =~ /\Q$_\E/i) {
>>
>> it quotes the string correctly before processing the regex


> Will this work even if $searchstring contains an "reserved"
> character, or should I:
> 
> $newsearchstring =~ /\Q$searchstring\E/i)


Please use copy/paste with *real* code.

Was the parenthesis supposed to be a semicolon?


> if ($newsearchstring =~ /\Q$_\E/i) {


Backslash escapes, such as \Q and \n, work in "double quotish" strings.

The match operator is "double quotish", but you can also use them in
actual double-quoted strings.

So, use one in a double-quoted string and then print the string
to see what it did:

   my $searchstring = 'open paren(';
   my $str = "\Q$searchstring";
   print "$str\n";


See also the named function that does the same thing:

   perldoc -f quotemeta


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 22 Oct 2003 00:58:46 +0200
From: "Mark" <admin@asarian-host.net>
Subject: Stale data in DB_File?
Message-Id: <gdadnSRpi5ezJwiiRVn-hg@giganews.com>

Hello,

I was wondering whether someone could explain to me a weird problem I am
having with DB_File (Perl 5.8.0).

Okay. A daemon uses this:

use DB_File;
use Fcntl;

tie %drac, DB_File, '/usr/local/etc/dracd.db', O_RDONLY, 0440, $DB_BTREE;

Within the daemon I then check like this:

if ($drac{'192.168.0.1'}) {
    ...

Works fine. Except, that when I delete an entry (with an external program,
also using DB_File), like so,

delete $drac{'192.168.0.1'};

Then, within the daemon the entry still exists! And vice versa: if I add an
entry to the dabase, then, within the daemon, this addition is not seen.
Within the daemon I do this, for test purposes:

foreach (sort keys %drac) {
    write_syslog ("$_, $drac{$_}");
}

The only way I was able to avoid stale data, is to evoke the tie call, each
time, within the subroutine that tests $drac{'entry'}. Surely I am not
supposed to do that, right? I thought you had to do the tie only once, after
which %drac stays tied throughout the process.

The drac database, of course, is updated from the outside (like my test
programs did).

Please, tell me what I'm missing and/or doing wrong.

Thanks!

- Mark




------------------------------

Date: Wed, 22 Oct 2003 03:14:19 GMT
From: Bob Walton <invalid-email@rochester.rr.com>
Subject: Re: Stale data in DB_File?
Message-Id: <3F95F448.5080505@rochester.rr.com>

Mark wrote:

> Hello,
> 
> I was wondering whether someone could explain to me a weird problem I am
> having with DB_File (Perl 5.8.0).
> 
> Okay. A daemon uses this:
> 
> use DB_File;
> use Fcntl;
> 
> tie %drac, DB_File, '/usr/local/etc/dracd.db', O_RDONLY, 0440, $DB_BTREE;
> 
> Within the daemon I then check like this:
> 
> if ($drac{'192.168.0.1'}) {
>     ...
> 
> Works fine. Except, that when I delete an entry (with an external program,
> also using DB_File), like so,
> 
> delete $drac{'192.168.0.1'};
> 
> Then, within the daemon the entry still exists! And vice versa: if I add an
> entry to the dabase, then, within the daemon, this addition is not seen.
> Within the daemon I do this, for test purposes:
> 
> foreach (sort keys %drac) {
>     write_syslog ("$_, $drac{$_}");
> }
> 
> The only way I was able to avoid stale data, is to evoke the tie call, each
> time, within the subroutine that tests $drac{'entry'}. Surely I am not
> supposed to do that, right? I thought you had to do the tie only once, after
> which %drac stays tied throughout the process.
> 
> The drac database, of course, is updated from the outside (like my test
> programs did).
> 
> Please, tell me what I'm missing and/or doing wrong.
> 
> Thanks!
> 
> - Mark
> 
> 
> 

When you are reading and writing DBM-type files (or any other type of 
file, for that matter) from more than one process or thread 
simultaneously, you need to treat all the operations between the tie and 
the untie as atomic from a file locking perspective.  See:

    perldoc -f flock
    perldoc -q lock
    perldoc DB_File

So the basic operations are:  In a given process, establish a lock, then 
tie the DBM-type file, do whatever to it (read, write), untie the 
DBM-type file, and remove the lock.  For best results, use a separate 
empty file (or a file whose contents don't matter) for locking purposes 
and only touch the locked DBM-type file when your process has a lock on 
the lock file.  Be sure to very carefully read all your system's 
documentation about file locking -- that topic probably varies more than 
any other amongst the various operating systems.  Note that some OS's 
require the lock file be opened for write to establish an exclusive lock 
and that it be opened for read to establish a shared lock.  And some 
infamous wanna-be OS's don't support file locking at all, in which case 
you cannot safely use file I/O in multiple processes simultaneously (in 
that case, get an OS).  Be sure and test your locking scheme to be 
certain it is functional.

Note also that you risk a lot more than just loss of data synchronicity 
("stale data") if you don't lock -- you can easily corrupt the file.

-- 
Bob Walton
Email: http://bwalton.com/cgi-bin/emailbob.pl



------------------------------

Date: Tue, 21 Oct 2003 17:23:11 -0500
From: tadmc@augustmail.com (Tad McClellan)
Subject: Re: Taint - having some real trouble here, taint/perl experts, please help
Message-Id: <slrnbpbcef.1ro.tadmc@magna.augustmail.com>

Darren Dunham <ddunham@redwood.taos.com> wrote:
> Ben <2stormts@nemontel.net> wrote:

>>   exec("/usr/src/client/client",$p1,$p2,$p3,$p4);
>>   exit;
> 
> That exit line is never executed.


That exit line is never executed _unless_ the exec() failed.  :-)


-- 
    Tad McClellan                          SGML consulting
    tadmc@augustmail.com                   Perl programming
    Fort Worth, Texas


------------------------------

Date: Wed, 22 Oct 2003 09:53:53 +1000
From: Matthew Braid <mb@uq.net.au>
Subject: Taint differences between 5.8.0 and 5.8.1?
Message-Id: <bn4gug$muq$1@bunyip.cc.uq.edu.au>

Hi all,

I was just trolling through my messages file recently and noticed that 
ever since I upgraded from 5.8.0 to 5.8.1 I've been getting a lot of 
'Insecure dependency' (ie taint) errors from one of my daemon scripts.

On closer inspection I narrowed it down to an exec call in MIME::Lite. 
This chunk of code had not produced an error before while taint mode is 
on (and in fact the comments around that chunk of code basically said 
'Run sendmail in a taint-safe fashion').

Has exec become more taint-aware between 5.8.0 and 5.8.1?

I worked around it by untainting everything passed to exec, but it was a 
little surprising and I haven't seen anything mentioned about the change 
in documentation.

MB



------------------------------

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 5693
***************************************


home help back first fref pref prev next nref lref last post