[23672] in Perl-Users-Digest

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

Perl-Users Digest, Issue: 5879 Volume: 10

daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Mon Dec 1 14:10:55 2003

Date: Mon, 1 Dec 2003 11:10:10 -0800 (PST)
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, 1 Dec 2003     Volume: 10 Number: 5879

Today's topics:
        I can't flock, it returns 0, any ideas. <someone@somewhere.nb.ca>
    Re: I can't flock, it returns 0, any ideas. <jim.mozley@exponential-e.com>
    Re: I can't flock, it returns 0, any ideas. <glex_nospam@qwest.invalid>
    Re: I can't flock, it returns 0, any ideas. <jim.mozley@exponential-e.com>
    Re: I can't flock, it returns 0, any ideas. <jim.mozley@exponential-e.com>
    Re: I can't flock, it returns 0, any ideas. <usenet@morrow.me.uk>
    Re: I can't flock, it returns 0, any ideas. (Randal L. Schwartz)
    Re: I can't flock, it returns 0, any ideas. <usenet@morrow.me.uk>
    Re: I can't flock, it returns 0, any ideas. <someone@somewhere.nb.ca>
    Re: I can't flock, it returns 0, any ideas. <someone@somewhere.nb.ca>
    Re: I can't flock, it returns 0, any ideas. <usenet@morrow.me.uk>
        pack, Win32 registry & binary data (woof)
        Perl et Telnet (ThERiZla)
        Question about error in PerlScript <bluecat22@go.com>
        question about installation of GD::Text on cygwin (coul (Upstart)
    Re: question about installation of GD::Text on cygwin ( <randy@theoryx5.uwinnipeg.ca>
    Re: script works from prompt but not through telnet (Eric Lewton)
        Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)

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

Date: Mon, 01 Dec 2003 16:11:32 GMT
From: "Guy" <someone@somewhere.nb.ca>
Subject: I can't flock, it returns 0, any ideas.
Message-Id: <UKJyb.2336$IF6.101378@ursa-nb00s0.nbnet.nb.ca>

I can't flock, it returns 0, any ideas.


This was suppose to be a small test script that would lock a file, the loop
for a certain amount of time, and then close the file.
I wanted to run this script to see if it would affect my other perl script
whi is trying to access the same file.

From what I read, I'm assuming that when you close a file, it also unlocks
it, so I'm guessing that you don't really have to unlock it before closing
it.
Just so you know '$l' is lower case $L. I guess i should choose more legible
scalars. The font here is pretty bad!

Anyway, my HTML page submits the variables f and l.
Variable f is just a delay variable, value of 50 give me like a 10 to 15
second delay. (so I thought the file would be locked for 10 to 15 seconds)
Variable l contains the operation I want to use on flock.
I tried 1,2, and 8, but it doesn't appear to lock the file, and the flock
function returns 0.
I'm not sure about 4 (NB), I think you have to add it to the 1, 2, or 8.
So I even tried with 5, and 6 but it still returns 0.
At first, this was actually hard coded, my command actually read $chk=flock
LCKFILE,2;

When I telnet to the server and do ls -l, it shows that the file has
_rw_rw_rw_
Is there anything I am missing.
This is my first attempt at using flock.
Guy Doucet



#!/usr/local/bin/perl -w

use CGI qw(:standard);
no warnings;

print header();

$fd="../data";
$lockfil="$fd/lock.txt";

$temp=$ENV{'QUERY_STRING'};
@pairs=split(/&/,$temp);
foreach $item(@pairs)
  {
  ($key,$content)=split(/=/,$item,2);$CONFILTERED=~tr/+/
/;$CONFILTERED=~s/%(..)/pack("c",hex($1))/ge;
  if($key eq "f"){$f=$content;}
  if($key eq "l"){$l=$content;}
  }

print"<HTML><BODY>\n";

$gchk=locksys();         # Lock file access
if($gchk==0){while($f>0){$f--;$t=64000;while($t>0){$t--;$a = 1234;$b = 31;$c
= $a * $b / 3;}}&unlocksys;}

print"Done!<BR></BODY></HTML>\n";

sub locksys{
  my $chk=3840;
  if(-d "$fd"){$chk=3584;if(open(LCKFILE,"$lockfil")){$chk=flock
LCKFILE,$l;}}
  print"chk=:$chk:<BR>\n";
  return $chk;
  }

sub unlocksys{
  close LCKFILE;
  }





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

Date: Mon, 01 Dec 2003 16:42:03 +0000
From: Jim Mozley <jim.mozley@exponential-e.com>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <bqfqvr$22hhoq$1@ID-201189.news.uni-berlin.de>

Guy wrote:


> This was suppose to be a small test script that would lock a file, the loop
> for a certain amount of time, and then close the file.
> I wanted to run this script to see if it would affect my other perl script
> whi is trying to access the same file.

Assuming this is on unix why not use flock?

Jim


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

Date: Mon, 01 Dec 2003 10:50:44 -0600
From: "J. Gleixner" <glex_nospam@qwest.invalid>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <SfKyb.748$eD2.15638@news.uswest.net>

Guy wrote:
> I can't flock, it returns 0, any ideas.

First, have open and flock tell you why it's failing.

Read the perlopentut

	perldoc perlopentut

Oh, and since you're using CGI.pm, don't do your own parsing of 
QUERY_STRING, (foreach..@pairs.. stuf..) just use the param method 
provided by CGI.

	perldoc CGI



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

Date: Mon, 01 Dec 2003 16:48:01 +0000
From: Jim Mozley <jim.mozley@exponential-e.com>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <bqfrb6$218pqo$1@ID-201189.news.uni-berlin.de>

Jim Mozley wrote:
> Guy wrote:
> 
> 
>> This was suppose to be a small test script that would lock a file, the 
>> loop
>> for a certain amount of time, and then close the file.
>> I wanted to run this script to see if it would affect my other perl 
>> script
>> whi is trying to access the same file.
> 
> 
> Assuming this is on unix why not use flock?
> 
> Jim

ignore me I'm having one of those days, next time I'll read the bloody code!


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

Date: Mon, 01 Dec 2003 16:57:12 +0000
From: Jim Mozley <jim.mozley@exponential-e.com>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <bqfrsd$224nsb$1@ID-201189.news.uni-berlin.de>

J. Gleixner wrote:

> Guy wrote:
> 
>> I can't flock, it returns 0, any ideas.
> 
> 
> First, have open and flock tell you why it's failing.
> 
> Read the perlopentut
> 
>     perldoc perlopentut

Not making excuses for myself really, but I missed the flock because it 
was buried somewhere in the code (as well as not enough coffee). I've 
used this, admitedley in a non-CGI script.

use Fcntl qw| :flock |;

my $file = 'testfile';

open(FILE, "> $file") or die "Cannot open file: $!";
flock(FILE, LOCK_EX);
print FILE "some text";
close FILE or die "Cannot close file $!"; # also releases lock

Jim


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

Date: Mon, 1 Dec 2003 17:22:53 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <bqftdd$p18$1@wisteria.csv.warwick.ac.uk>


"Guy" <someone@somewhere.nb.ca> wrote:
> I can't flock, it returns 0, any ideas.

man flock

| RETURN VALUE
|        On success, zero is returned. On error, -1 is returned and
|        errno is set appropriately.

This is what the syscall returns. Perl maps these values (0 and -1) to
"0 but true" and undef respectively. The upshot of this is that if you
say 'if (flock(...) == 0)' it will always be true: "0 but true" numifies
to 0, as does undef. The correct test is 'if (flock(...))': undef is
false, and "0 but true" is true (that's why Perl uses that special
string rather than the number 0).

> I wanted to run this script to see if it would affect my other perl script
> whi is trying to access the same file.

Note that flock() locks are advisory, so it won't affect your other
script unless that also uses flock. The rules governing locks are:

1. Locks don't affect anything except other locks: they don't stop
   anyone opening, reading, writing, deleting, etc. the file.

2. You can only hold a lock on an open file. (The details of what
   happens when you have several handles open on the same file depend
   on the underlying system: don't go there. :)

3. If someone holds a LOCK_EX lock, all attempts to get a lock will
   fail. (LOCK_EX means 'exclusive lock'.)

4. If someone holds a LOCK_SH lock, attempts to get a LOCK_EX lock
   will fail but attempts to get another LOCK_SH lock will
   succeed. (LOCK_SH means 'shared lock'.)

5. If you can't get the lock you are trying for, then if you specify
   LOCK_NB (use | rather than +, i.e. 'flock $FH, LOCK_SH | LOCK_NB)
   the flock call will fail, and if you don't flock will just not
   return until you can.

> From what I read, I'm assuming that when you close a file, it also unlocks
> it, so I'm guessing that you don't really have to unlock it before closing
> it.

That's right. Most uses of LOCK_UN are wrong.

> I tried 1,2, and 8, but it doesn't appear to lock the file, and the flock
> function returns 0.

Don't do this. Use the constants from Fcntl, both for readability and
portability:

> #!/usr/local/bin/perl -w
> 
> use CGI qw(:standard);

use Fcntl qw/:flock/;

> no warnings;

Why? Using '-w' and then 'no warnings' is particularly perverse... You
should have both these lines:
  use warnings;
  use strict;
and then you don't need '-w'.

> print header();
> 
> $fd="../data";

  my $fd = "../data";

Insert 'my' similarly for all the variables 'strict' complains about.

> $lockfil="$fd/lock.txt";
> 
> $temp=$ENV{'QUERY_STRING'};
> @pairs=split(/&/,$temp);
>
> foreach $item(@pairs)
>   {
>   ($key,$content)=split(/=/,$item,2);$CONFILTERED=~tr/+/
> /;$CONFILTERED=~s/%(..)/pack("c",hex($1))/ge;
>   if($key eq "f"){$f=$content;}
>   if($key eq "l"){$l=$content;}
>   }

NO. Since you're using CGI.pm, *USE* it. Read the docs if you don't
know how: perldoc CGI.

> print"<HTML><BODY>\n";
> 
> $gchk=locksys();         # Lock file access

[Indentation sorted out: you'll find code much easier to work with if
you indent properly]

> if($gchk==0) {

So here you just want
  if($gchk) {

>     while($f>0) {
>         $f--;
>         $t=64000;
>         while($t>0) {
>             $t--;
>             $a = 1234;
>             $b = 31;
>             $c = $a * $b / 3;
>         }
>     }

AARGH! No no no, this is not how you pause the script!
See 'perldoc -f sleep'.

>     &unlocksys;

Don't use &sub unless you know what it does and why you need it:
  unlocksys();

> }
> 
> print"Done!<BR></BODY></HTML>\n";
> 

[more indentation-adjusting]

> sub locksys{
>   my $chk=3840;
>   if(-d "$fd") {
>       $chk=3584;
>       if(open(LCKFILE,"$lockfil")) {

This will fail if lock.txt doesn't exist. Since you're just using it
for locking, you can just nuke it each time with
  open LCKFILE, ">$lockfil";
 .

>           $chk=flock LCKFILE,$l;

This is silly. You don't need to pass the type of lock to aquire in as
a CGI parameter. Those programs which only read whatever it is you are
locking should use
  $chk = flock LCKFILE, LOCK_SH;
and those that write should use
  $chk = flock LCKFILE, LOCK_EX;
 . The rules given above were designed with this in mind. If you are
just trying to make sure you have only one copy of your script running
at a time, use LOCK_EX.

>       }

If the open failed, don't you want to know why? Perl will tell you if
you ask it nicely:
        else {
            print "Open failed: $!";
        }

I would be very much inclined to structure this whole thing rather
differently. I would have:

sub locksys {
    my $file = shift;
    
    open my $FH, ">", $file or die "can't open lockfile: $!";
    flock $FH, LOCK_EX      or die "can't aquire lock: $!";

    return $FH;
}

There are several points here:

1. 'my $file = shift' means we take the file to lock as an argument.

2. 'my $FH' creates a what is called a 'lexical filehandle'. Basically
   this means that the file is automatically closed as soon as all
   references to it go out of scope, so you don't need &unlocksys any
   more. 

3. We return this filehandle from the sub, so that the file isn't just
   closed straight away (that would be rather silly). You use it like
   this:

#...program...

{
    my $LOCK = locksys("../data/lock.txt");

    #... do stuff that relies on having the lock
}
#... $LOCK goes out of scope here, so the file is closed and the lock
# lost.

4. If any of the syscalls fails, we 'die'. This will terminate the
   program with an error message. You can use the CGI::Carp module
   (see its docs) to get the error sent somewhere sensible when
   running CGI scripts.

   This is really a matter of style: you could just as well choose to
   return undef or something instead, and write your own error message
   with $! up in the main script. You may find this approach easier if
   you want to fail softly rather than aborting the script and don't
   feel like messing with eval {}.

5. I assume here that if flock fails it is a fatal error. If flock may
   fail non-fatally (either because you used LOCK_NB or because your
   system doesn't restart syscalls if you catch a signal) you will
   need to investigte the Errno module to find the reason for its
   failure, and take appropriate action.

Ben

-- 
perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
2047502190/'                                                 # ben@morrow.me.uk


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

Date: Mon, 01 Dec 2003 17:28:27 GMT
From: merlyn@stonehenge.com (Randal L. Schwartz)
To: Jim Mozley <jim.mozley@exponential-e.com>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <494d3a3c9da238b965627db70c34f1d3@news.teranews.com>

>>>>> "Jim" == Jim Mozley <jim.mozley@exponential-e.com> writes:

Jim> open(FILE, "> $file") or die "Cannot open file: $!";
Jim> flock(FILE, LOCK_EX);

This doesn't make any sense.  You've already potentially blown away
someone else's written data if they got the flock before you.

You cannot modify the file before obtaining the flock.  And "open >"
definitely modifies the file (truncating it).

"open >>" is probably what you wanted, followed by a seek FILE, 0, 0.

-- 
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: Mon, 1 Dec 2003 17:42:52 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <bqfuis$pra$1@wisteria.csv.warwick.ac.uk>


merlyn@stonehenge.com (Randal L. Schwartz) wrote:
> >>>>> "Jim" == Jim Mozley <jim.mozley@exponential-e.com> writes:
> 
> Jim> open(FILE, "> $file") or die "Cannot open file: $!";
> Jim> flock(FILE, LOCK_EX);
> 
> This doesn't make any sense.  You've already potentially blown away
> someone else's written data if they got the flock before you.

I think the file in question was just being used as a semaphore: i.e. it
never had any real data; and the 'create-if-nonexistent' semantics are
important.

> "open >>" is probably what you wanted, followed by a seek FILE, 0, 0.

Errr... that does something quite different, no? Perhaps you meant
'+<'? Or maybe 'truncate 0' after aquiring the lock.

If the file does contain data, then I would say that you have to use
sysopen, as you want O_CREAT | O_RDWR but not O_TRUNC:

sysopen FILE, $file, O_RDWR | O_CREAT or die $!;

Ben

-- 
       .  |  .
    \           /           The clueometer is reading zero.
  .               .
 __ <-----@       __                                           ben@morrow.me.uk


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

Date: Mon, 01 Dec 2003 17:43:47 GMT
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <n5Lyb.2372$IF6.104358@ursa-nb00s0.nbnet.nb.ca>

WOW!!!
Thanks to everyone for all the information.
I will try to put all or at least most of these suggestions to use.

With respect to flock, my perl 5 book says it returns 1 if true, and '' if
false, whatever that means.
In any case, I changed one thing and now it appears to work.

open(LCKFILE,"$lockfil");   # returns zero when I try to flock
open(LCKFILE,">$lockfil");   # returns one when I try to flock

As for the parsing, I thought it would be more portable by doing it the long
way.
I guess it's from my older days of writing, or maybe I was just doing it
wrong back then too!

Thanks for putting so much time to this.
Cheers all.
Guy Doucet


"Ben Morrow" <usenet@morrow.me.uk> wrote in message
news:bqftdd$p18$1@wisteria.csv.warwick.ac.uk...
>
> "Guy" <someone@somewhere.nb.ca> wrote:
> > I can't flock, it returns 0, any ideas.
>
> man flock
>
> | RETURN VALUE
> |        On success, zero is returned. On error, -1 is returned and
> |        errno is set appropriately.
>
> This is what the syscall returns. Perl maps these values (0 and -1) to
> "0 but true" and undef respectively. The upshot of this is that if you
> say 'if (flock(...) == 0)' it will always be true: "0 but true" numifies
> to 0, as does undef. The correct test is 'if (flock(...))': undef is
> false, and "0 but true" is true (that's why Perl uses that special
> string rather than the number 0).
>
> > I wanted to run this script to see if it would affect my other perl
script
> > whi is trying to access the same file.
>
> Note that flock() locks are advisory, so it won't affect your other
> script unless that also uses flock. The rules governing locks are:
>
> 1. Locks don't affect anything except other locks: they don't stop
>    anyone opening, reading, writing, deleting, etc. the file.
>
> 2. You can only hold a lock on an open file. (The details of what
>    happens when you have several handles open on the same file depend
>    on the underlying system: don't go there. :)
>
> 3. If someone holds a LOCK_EX lock, all attempts to get a lock will
>    fail. (LOCK_EX means 'exclusive lock'.)
>
> 4. If someone holds a LOCK_SH lock, attempts to get a LOCK_EX lock
>    will fail but attempts to get another LOCK_SH lock will
>    succeed. (LOCK_SH means 'shared lock'.)
>
> 5. If you can't get the lock you are trying for, then if you specify
>    LOCK_NB (use | rather than +, i.e. 'flock $FH, LOCK_SH | LOCK_NB)
>    the flock call will fail, and if you don't flock will just not
>    return until you can.
>
> > From what I read, I'm assuming that when you close a file, it also
unlocks
> > it, so I'm guessing that you don't really have to unlock it before
closing
> > it.
>
> That's right. Most uses of LOCK_UN are wrong.
>
> > I tried 1,2, and 8, but it doesn't appear to lock the file, and the
flock
> > function returns 0.
>
> Don't do this. Use the constants from Fcntl, both for readability and
> portability:
>
> > #!/usr/local/bin/perl -w
> >
> > use CGI qw(:standard);
>
> use Fcntl qw/:flock/;
>
> > no warnings;
>
> Why? Using '-w' and then 'no warnings' is particularly perverse... You
> should have both these lines:
>   use warnings;
>   use strict;
> and then you don't need '-w'.
>
> > print header();
> >
> > $fd="../data";
>
>   my $fd = "../data";
>
> Insert 'my' similarly for all the variables 'strict' complains about.
>
> > $lockfil="$fd/lock.txt";
> >
> > $temp=$ENV{'QUERY_STRING'};
> > @pairs=split(/&/,$temp);
> >
> > foreach $item(@pairs)
> >   {
> >   ($key,$content)=split(/=/,$item,2);$CONFILTERED=~tr/+/
> > /;$CONFILTERED=~s/%(..)/pack("c",hex($1))/ge;
> >   if($key eq "f"){$f=$content;}
> >   if($key eq "l"){$l=$content;}
> >   }
>
> NO. Since you're using CGI.pm, *USE* it. Read the docs if you don't
> know how: perldoc CGI.
>
> > print"<HTML><BODY>\n";
> >
> > $gchk=locksys();         # Lock file access
>
> [Indentation sorted out: you'll find code much easier to work with if
> you indent properly]
>
> > if($gchk==0) {
>
> So here you just want
>   if($gchk) {
>
> >     while($f>0) {
> >         $f--;
> >         $t=64000;
> >         while($t>0) {
> >             $t--;
> >             $a = 1234;
> >             $b = 31;
> >             $c = $a * $b / 3;
> >         }
> >     }
>
> AARGH! No no no, this is not how you pause the script!
> See 'perldoc -f sleep'.
>
> >     &unlocksys;
>
> Don't use &sub unless you know what it does and why you need it:
>   unlocksys();
>
> > }
> >
> > print"Done!<BR></BODY></HTML>\n";
> >
>
> [more indentation-adjusting]
>
> > sub locksys{
> >   my $chk=3840;
> >   if(-d "$fd") {
> >       $chk=3584;
> >       if(open(LCKFILE,"$lockfil")) {
>
> This will fail if lock.txt doesn't exist. Since you're just using it
> for locking, you can just nuke it each time with
>   open LCKFILE, ">$lockfil";
> .
>
> >           $chk=flock LCKFILE,$l;
>
> This is silly. You don't need to pass the type of lock to aquire in as
> a CGI parameter. Those programs which only read whatever it is you are
> locking should use
>   $chk = flock LCKFILE, LOCK_SH;
> and those that write should use
>   $chk = flock LCKFILE, LOCK_EX;
> . The rules given above were designed with this in mind. If you are
> just trying to make sure you have only one copy of your script running
> at a time, use LOCK_EX.
>
> >       }
>
> If the open failed, don't you want to know why? Perl will tell you if
> you ask it nicely:
>         else {
>             print "Open failed: $!";
>         }
>
> I would be very much inclined to structure this whole thing rather
> differently. I would have:
>
> sub locksys {
>     my $file = shift;
>
>     open my $FH, ">", $file or die "can't open lockfile: $!";
>     flock $FH, LOCK_EX      or die "can't aquire lock: $!";
>
>     return $FH;
> }
>
> There are several points here:
>
> 1. 'my $file = shift' means we take the file to lock as an argument.
>
> 2. 'my $FH' creates a what is called a 'lexical filehandle'. Basically
>    this means that the file is automatically closed as soon as all
>    references to it go out of scope, so you don't need &unlocksys any
>    more.
>
> 3. We return this filehandle from the sub, so that the file isn't just
>    closed straight away (that would be rather silly). You use it like
>    this:
>
> #...program...
>
> {
>     my $LOCK = locksys("../data/lock.txt");
>
>     #... do stuff that relies on having the lock
> }
> #... $LOCK goes out of scope here, so the file is closed and the lock
> # lost.
>
> 4. If any of the syscalls fails, we 'die'. This will terminate the
>    program with an error message. You can use the CGI::Carp module
>    (see its docs) to get the error sent somewhere sensible when
>    running CGI scripts.
>
>    This is really a matter of style: you could just as well choose to
>    return undef or something instead, and write your own error message
>    with $! up in the main script. You may find this approach easier if
>    you want to fail softly rather than aborting the script and don't
>    feel like messing with eval {}.
>
> 5. I assume here that if flock fails it is a fatal error. If flock may
>    fail non-fatally (either because you used LOCK_NB or because your
>    system doesn't restart syscalls if you catch a signal) you will
>    need to investigte the Errno module to find the reason for its
>    failure, and take appropriate action.
>
> Ben
>
> --
> perl -e'print map {/.(.)/s} sort unpack "a2"x26, pack "N"x13,
> qw/1632265075 1651865445 1685354798 1696626283 1752131169 1769237618
> 1801808488 1830841936 1886550130 1914728293 1936225377 1969451372
> 2047502190/'                                                 #
ben@morrow.me.uk




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

Date: Mon, 01 Dec 2003 17:48:37 GMT
From: "Guy" <someone@somewhere.nb.ca>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <V9Lyb.2376$IF6.104263@ursa-nb00s0.nbnet.nb.ca>

Actually, it _was_ just a dummy file, but yes what you say makes sense.
thanks again to all.


"Randal L. Schwartz" <merlyn@stonehenge.com> wrote in message
news:494d3a3c9da238b965627db70c34f1d3@news.teranews.com...
> >>>>> "Jim" == Jim Mozley <jim.mozley@exponential-e.com> writes:
>
> Jim> open(FILE, "> $file") or die "Cannot open file: $!";
> Jim> flock(FILE, LOCK_EX);
>
> This doesn't make any sense.  You've already potentially blown away
> someone else's written data if they got the flock before you.
>
> You cannot modify the file before obtaining the flock.  And "open >"
> definitely modifies the file (truncating it).
>
> "open >>" is probably what you wanted, followed by a seek FILE, 0, 0.
>
> --
> 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: Mon, 1 Dec 2003 18:24:54 +0000 (UTC)
From: Ben Morrow <usenet@morrow.me.uk>
Subject: Re: I can't flock, it returns 0, any ideas.
Message-Id: <bqg11m$rqt$2@wisteria.csv.warwick.ac.uk>


"Guy" <someone@somewhere.nb.ca> wrote:
> With respect to flock, my perl 5 book says it returns 1 if true, and '' if
> false, whatever that means.

You're right, so it does... I've only ever tested the return for
truth.

OK, what I said holds about /most/ syscalls in Perl... :)

Ben

-- 
   Although few may originate a policy, we are all able to judge it.
                                             - Pericles of Athens, c.430 B.C.
  ben@morrow.me.uk


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

Date: 1 Dec 2003 06:47:34 -0800
From: drubnone@yahoo.com (woof)
Subject: pack, Win32 registry & binary data
Message-Id: <7b21a826.0312010647.6248a666@posting.google.com>

I need an example on how to collect and process REG_BINARY data
in a Win32 registry.  The registry value in question reads:

TimeOfLastScan   REG_BINARY   21 0a 1e 0d 00 1e 00 00

It appears to be 8 bytes... an unsigned long ("L")?

Reading strings seems easy enough as in
 my $parent = $rkeyNorton->{"CurrentVersion//Parent"};

I did try and read this binary value with (cvKey set to CurrentVersion);

(my $gvtimeOfLastScan, my $type) = $cvKey->GetValue("TimeOfLastScan");

But have been unable to feed localtime() anything that gets
me my date string.  I know I'm not packing this correctly.

Thanks.


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

Date: 1 Dec 2003 10:39:24 -0800
From: cool_ian10@hotmail.com (ThERiZla)
Subject: Perl et Telnet
Message-Id: <42f55bd6.0312011039.5cb84039@posting.google.com>

Hi,

I do a connection on the server witn Telnet.
My problem is when I execute a command on command prompt. 
This is my command : my @outputcreateUser = $telnet->cmd($createUser);
I want obtain the result of the command but when I print the array
@outputCreateUser there is nothing in the array.

This is my code to connect to the server:
	## Create a Net::Telnet object
        use Net::Telnet ();
	$telnet = new Net::Telnet (Timeout => 20,
				Input_log  => $fileInput,
				Output_log => $fileOutput,
				Errmode => 'return',
				Prompt => $prompt);
	if (! defined $telnet) {
		die "Unable to create telnet object for $host";
	}
	
	$telnet->open($host);
	if ($msg = $telnet->errmsg) {
		die "Unable to open telnet to $host $msg";
	}
	
	$telnet->login($username, $password);
	if ($msg = $telnet->errmsg) {
		die "Unable to login to $host $msg PWD: $password";
	}
	return $telnet;
 

I like know if I do something wrong.
An explication and an example will be appreciate.
Thanks


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

Date: Mon, 1 Dec 2003 10:05:35 -0500
From: "Blue Cat" <bluecat22@go.com>
Subject: Question about error in PerlScript
Message-Id: <bqflup01tar@enews3.newsguy.com>

In the process of trying to learn PerlScript I found the file plhello.htm,
which came with my ActivePerl distribution. This file was in the
c:\Perl\eg\ie3examples folder.

When I tried to execute the file, I got an error message from Internet
Explorer 5,
"Can't call method 'Text1' on an undefined value at (eval 5) line 4."

Is there something missing from either this file, or from my distribution to
cause this error message?




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

Date: 1 Dec 2003 06:15:07 -0800
From: stimonyhall@netscape.net (Upstart)
Subject: question about installation of GD::Text on cygwin (could be a Makefile q)
Message-Id: <79516caa.0312010615.143302a3@posting.google.com>

Hi

For background: I am trying to install a few modules with an
environment of Cygwin w/ windows 2000. The module I am stuck on is
GD::Text.

tried this post on the *.modules list with no luck.

Went to cygwin to download latest and greatest code, and they seem to
package freetype and the GD library now. So I downloaded them and
installed, then was able to successfully build GD.pm.

Now I downloaded GD::Text 0.86. I do a 'perl Makefile.PL' and it won't
drop/create a Makefile. I downloaded 0.85 and got the same results:

$ perl Makefile.PL
Checking if your kit is complete...
Looks good

$


that's it... no Makefile. no error messages. I am building other
modules (Like GD) and this step builds a Makefile with those modules.

How would I trouble shoot this? I guess it would have to do with the
ExtUtils::MakeMaker module.... but I don't know how to troubleshoot
this kind of fundamental problem.

JIM


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

Date: Mon, 1 Dec 2003 09:43:23 -0600
From: "Randy Kobes" <randy@theoryx5.uwinnipeg.ca>
Subject: Re: question about installation of GD::Text on cygwin (could be a Makefile q)
Message-Id: <vkJyb.33803$MW5.49636@news1.mts.net>

"Upstart" <stimonyhall@netscape.net> wrote in message
 news:79516caa.0312010615.143302a3@posting.google.com...
> Hi
>
> For background: I am trying to install a few modules with an
> environment of Cygwin w/ windows 2000. The module I am stuck on is
> GD::Text.
>
> tried this post on the *.modules list with no luck.
>
> Went to cygwin to download latest and greatest code, and they seem to
> package freetype and the GD library now. So I downloaded them and
> installed, then was able to successfully build GD.pm.
>
> Now I downloaded GD::Text 0.86. I do a 'perl Makefile.PL' and it won't
> drop/create a Makefile. I downloaded 0.85 and got the same results:
>
> $ perl Makefile.PL
> Checking if your kit is complete...
> Looks good
>
> $
>
> that's it... no Makefile. no error messages. I am building other
> modules (Like GD) and this step builds a Makefile with those modules.
>
> How would I trouble shoot this? I guess it would have to do with the
> ExtUtils::MakeMaker module.... but I don't know how to troubleshoot
> this kind of fundamental problem.

If you comment out all the stuff at the beginning of Makefile.PL
involving eval{}, and just leave the WriteMakefile() call in, is a
Makefile produced?

best regards,
randy kobes





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

Date: 1 Dec 2003 06:36:32 -0800
From: lewtone@myfastmail.com (Eric Lewton)
Subject: Re: script works from prompt but not through telnet
Message-Id: <3df67682.0312010636.6d1156b2@posting.google.com>

But then it turned out that wasn't it, so if anyone has this problem,
this is what I had to do:


CODE

#!/[full address of a more modern version of perl]

use lib [full address of library directory that I created]

Then I had to use the modules own proxy settings (in manual).

Do all stuff here.

END CODE


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

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


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