Re: File Access + Thread Safe

2007-04-22 Thread John W. Krahn
yitzle wrote:
 I got a CGI script that is being used by multiple users.
 It reads/writes data to a database (text file).
 When it reads, it reads the entire file, and when it writes, it
 tuncrates and rewrites the entire file.
 Can/will this screw up the file if two people try to write to the file
 at the same time?
 How do I prevent problems? (SQL/MySQL is not an option)

perldoc -q \block



John
-- 
Perl isn't a toolbox, but a small machine shop where you can special-order
certain sorts of tools at low cost and in short order.   -- Larry Wall

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




cpanplus module cyclic dependency

2007-04-22 Thread yaron
Hi,

I tried to install CPANPLUS with my cpan module. The installation ended with 
the following error:

Recursive dependency detected:s/Autoflush.pm 
blib/lib/CPANPLUS/Internals/Utils/ACPANPLUS

- K/KA/KANE/CPANPLUS-0.78.tar.gzb/lib/CPANPLUS/Module/Fake.pm

- CPANPLUS::Shell::Defaultb/lib/CPANPLUS/Error.pm

- K/KA/KANE/CPANPLUS-0.78.tar.gz..pm blib/lib/CPANPLUS/Internals/Constants.pm

Cannot continue.Dist/Base.pm blib/lib/CPANPLUS/Dist/Base.pm

I am tring to install cpanplus on a cygwin. 

Has anyone a clue for that?

Best regards,

Yaron Kahanovitch

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




testing return values

2007-04-22 Thread Mike Lesser
Hiya. I'm looking for the correct Perl style for testing and storing  
a return value in a control statement. The solution in any other  
language is pretty obvious, but I get the distinct impression that  
there's a 'right' way in Perl...


Let's say I want to test a scalar returned from a subroutine, and  
also keep a copy for my own use:


 $scalar = sub( $argument );

 if( $scalar ){
 }

Naturally that's no big deal. Now let's say I have a tree I want to  
traverse, or some similar open-ended thing to evaluate, and want to  
run it until a condition is reached..


 while( read_tree( $argument ){
 }

Again no biggie. The problem is if I want to keep the result.  
Obviously I can't do this:


while( $tree_element = read_tree( $argument ) ){
   do_something( $tree_element );
}

I can come up with a brute-force solution of course, but there's  
probably a better, Perlish way that I'm not aware of. In addition, I  
don't expect a return value from some module to be consistently  
undefined or zero; it could change under some circumstances. This  
makes me think that the problem has been dealt with long ago, and  
just doesn't stick out in the llama/alpaca/whatever books.


Hopefully I explained this correctly!







--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: testing return values

2007-04-22 Thread yitzle

Now, why can't you do this?


while( $tree_element = read_tree( $argument ) ){
   do_something( $tree_element );
}


I would certainly use it. In C this is called operation overflow or something...


On 4/22/07, Mike Lesser [EMAIL PROTECTED] wrote:

Hiya. I'm looking for the correct Perl style for testing and storing
a return value in a control statement. The solution in any other
language is pretty obvious, but I get the distinct impression that
there's a 'right' way in Perl...

Let's say I want to test a scalar returned from a subroutine, and
also keep a copy for my own use:

  $scalar = sub( $argument );

  if( $scalar ){
  }

Naturally that's no big deal. Now let's say I have a tree I want to
traverse, or some similar open-ended thing to evaluate, and want to
run it until a condition is reached..

  while( read_tree( $argument ){
  }

Again no biggie. The problem is if I want to keep the result.
Obviously I can't do this:

while( $tree_element = read_tree( $argument ) ){
do_something( $tree_element );
}

I can come up with a brute-force solution of course, but there's
probably a better, Perlish way that I'm not aware of. In addition, I
don't expect a return value from some module to be consistently
undefined or zero; it could change under some circumstances. This
makes me think that the problem has been dealt with long ago, and
just doesn't stick out in the llama/alpaca/whatever books.

Hopefully I explained this correctly!



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/




Re: testing return values

2007-04-22 Thread Rob Dixon

Mike Lesser wrote:
Hiya. I'm looking for the correct Perl style for testing and storing a 
return value in a control statement. The solution in any other language 
is pretty obvious, but I get the distinct impression that there's a 
'right' way in Perl...


Let's say I want to test a scalar returned from a subroutine, and also 
keep a copy for my own use:


 $scalar = sub( $argument );

 if( $scalar ){
 }

Naturally that's no big deal. Now let's say I have a tree I want to 
traverse, or some similar open-ended thing to evaluate, and want to run 
it until a condition is reached..


 while( read_tree( $argument ){
 }

Again no biggie. The problem is if I want to keep the result. Obviously 
I can't do this:


while( $tree_element = read_tree( $argument ) ){
   do_something( $tree_element );
}

I can come up with a brute-force solution of course, but there's 
probably a better, Perlish way that I'm not aware of. In addition, I 
don't expect a return value from some module to be consistently 
undefined or zero; it could change under some circumstances. This makes 
me think that the problem has been dealt with long ago, and just doesn't 
stick out in the llama/alpaca/whatever books.


Hopefully I explained this correctly!


while (my $x = func()) {
 :
}

is perfectly valid. In Perl every operator returns a value, and the assignment
operator is no exception. It's value is the expression on the left of the equals
sign, and it's even an lvalue so you can do things like

 ($x = 3)++;

leaving $x with a value of four. This sort of thing is more useful for things 
like

 $p = $q = 'A';

which is the same as

 $p = ($q = 'A');

or

 $q = 'A'; $p = $q;

But the bottom line is that your while loop is quite valid.

HTH,

Rob


--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/