Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

File not being written to and no errors?
I have a file I am trying to read and write to, it's obviously opening
it ie.. No errors but not writing to it.

Since no errors are being produced I can't figure out why? 

In short I am reading the file to see if I previously sent an email
concerning a "name" and if I have then don't send another email, if I
have not then do send an email. 

I am pretty sure of the logic as I receive the email, but it is not
writing the new "name" to the file.

 

Above and below, I am opening another file read/write in the same way
and it works just fine. Any suggestions on how to check what's going on?
I am using strict, warnings and diagnostics and everything appears to be
clear.

 

File:

-rwxrwxrwx    1 root     root           11 Jul 28 08:59 sent

 

1)

#!/usr/bin/perl

use strict;

use warnings;

use diagnostics;

use Net::NBName;

use Fcntl ':flock';

use Net::Ping::External qw(ping);

our ($d,$m,$y)=(localtime(time-86400))[3..5];$m+=1;$y+=1900;

...

...

2)

our $done='/var/scripts/snmp/sent';

our %sent=();

...

...

3)

open (DONE,"+>>$done") or die "Cannot open file: $!";

flock (DONE, 1);

foreach (<DONE> ){

chomp($_);

$sent{$_}="";

}

....

...

if (exists $sent{$mapn}){

}else{

...

...

4)

}elsif($ns && ($ns->as_string =~ /^(.*)\s*\<00\>/i)) {

push @mailbody, "AN
UNAUTHORIZED Device Was Detected\n";

push @mailbody,
"$maprh,$maprb,$maprp,$maprm,$mapip,$1\n";

print DONE "$1\n";

 

...

...

5)

...

flock(DONE, 8);

close(DONE);

...

 

 

 

Thanks,

Rich

 



Report this thread to moderator Post Follow-up to this message
Old Post
Arichmond
07-29-04 01:55 PM


Re: File not being written to and no errors?
On Jul 29, arichmond(contr-ird) said:

>I have a file I am trying to read and write to, it's obviously opening
>it ie.. No errors but not writing to it.
>
> Since no errors are being produced I can't figure out why?

You are opening a file for appending and reading.  But you forgot (or
didn't know) that you start out at the *end* of the file.

>open (DONE,"+>>$done") or die "Cannot open file: $!";
>
>        flock (DONE, 1);

You should really be using Fnctl.pm's file locking constants instead of
numbers here.

Anyway, here is where you should say:

s DONE, 0, 0;

to rewind to the beginning of the file.

>        foreach (<DONE> ){

Don't do that.  Use a while loop instead, PLEASE.

--
Jeff "japhy" Pinyan         %  How can we ever be the sold short or
RPI Acacia Brother #734     %  the cheated, we who for every service
http://japhy.perlmonk.org/  %  have long ago been overpaid?
http://www.perlmonks.org/   %    -- Meister Eckhart


Report this thread to moderator Post Follow-up to this message
Old Post
Jeff 'Japhy' Pinyan
07-29-04 08:56 PM


RE: File not being written to and no errors?
On Jul 29, japhy@perlmonk.org said:
 

I didn't thanks for the tip

>open (DONE,"+>>$done") or die "Cannot open file: $!";
>
>        flock (DONE, 1); 

Thanks, I read the perldocs and all the referring docs and understand
now what I am really trying to do
 

Fixed this and all the others throughout my script and it works
beautifully now, thanks for the help.


Report this thread to moderator Post Follow-up to this message
Old Post
Arichmond
07-29-04 08:56 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

PERL Beginners archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 04:31 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.