Re: Won't write IP address to file

2002-01-16 Thread John W. Krahn

"K.L. Hayes" wrote:
> 
> Hello All,

Hello,

> Could somebody please help me figure out why the following code will
> not write the IP address to a file?
> 
> I've verified that the code can find the file, open it & overwrite any
> junk/test data already there with nothing. I've also printed out the
> IP address on the previous page using just the print statement.
> 
> 
> sub pcheck {
> if (param('pwd') eq $pw ) {
> open  (CHECK,">${path}dmp.dat") || die "Cannot open dmp.dat: $!";
> flock (CHECK, 2) if ($flock);

use Fcntl ':flock';

if ( $flock ) {
flock( CHECK, LOCK_EX ) or die "Cannot lock dmp.dat: $!";
}


> while () {

You need this line only if you are reading data IN from a file, not
writing OUT to a file.


> print "$ENV{'REMOTE_ADDR'}"; }

print CHECK "$ENV{'REMOTE_ADDR'}";


> close (CHECK);
> flock (CHECK, 8) if ($flock);

There is no point in trying to unlock the file now, the close() has
already unlocked it.


> } else  { &invalid_info; }

  } else  { invalid_info() }

> &ad2;

  ad2();

When you call subroutines you shouldn't use an ampersand unless you
understand how and why it behaves differently.

perldoc perlsub


> }
> 
> 
> All help is appreciated. Thank you for your time.



John
-- 
use Perl;
program
fulfillment

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




RE: Won't write IP address to file

2002-01-16 Thread Hanson, Robert

It looks like you forgot to specify the file handle when printing.

print CHECK "$ENV{'REMOTE_ADDR'}"; }

Rob


-Original Message-
From: K.L. Hayes [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, January 16, 2002 6:23 PM
To: [EMAIL PROTECTED]
Subject: Won't write IP address to file


Hello All,

Could somebody please help me figure out why the following code will
not write the IP address to a file?

I've verified that the code can find the file, open it & overwrite any
junk/test data already there with nothing. I've also printed out the
IP address on the previous page using just the print statement.


sub pcheck {
if (param('pwd') eq $pw ) {
open  (CHECK,">${path}dmp.dat") || die "Cannot open dmp.dat: $!";
flock (CHECK, 2) if ($flock);
while () {
print "$ENV{'REMOTE_ADDR'}"; }
close (CHECK);
flock (CHECK, 8) if ($flock);
} else  { &invalid_info; }
&ad2;
}


All help is appreciated. Thank you for your time.

-- 
Best regards,
K.L. Hayes
mailto:[EMAIL PROTECTED]

+=+
+ "Only two things are infinite, the universe and +
+ human stupidity, and I'm not sure about the former."+
+ -- Albert Einstien  +
+=+



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]