http://qs321.pair.com?node_id=710968

o2bwise has asked for the wisdom of the Perl Monks concerning the following question:



Hi,

I am totally bamboozled by some text output I am getting for code I am troubleshooting for work.

Here are some lines of code:
if ($old_gnoc eq $gnoc) { print TEST "L782 - Counter: $counter_chk\t + $ip old_poller: $old_gnoc\tnew_poller: $gnoc\told_term: $old_group_t +erm\tnew_term: $term\n"; $dir = "$homeDir/$old_gnoc"; $file = "groupChange.txt"; open (GRPCHG,">>$dir/$file"); print GRPCHG "L782 - Counter: $counter_chk +\t $ip old_poller: $old_gnoc\tnew_poller: $gnoc\told_term: $old_group +_term\tnew_term: $term\n"; close (GRPCHG); }


OK, a bit on the code. There is no GRPCHG filehandle anywhere else in the program. There are no other print statements that start out with the string - L782.

Here is some relevant output for the file written to with the TEST file handle:

L782 - Counter: 7 128.212.27.1 old_poller: gnoc8 new_poller: gn +oc8 old_term: GSUS new_term: CLCEDSAM_C L782 - Counter: 8 128.212.28.1 old_poller: gnoc8 new_poller: gn +oc8 old_term: GSUS new_term: CLCEDSAM_C L782 - Counter: 9 128.212.28.46 old_poller: gnoc8 new_po +ller: gnoc8 old_term: GSUS new_term: CLCEDSAM_C L782 - Counter: 10 128.212.44.26 old_poller: gnoc8 new_po +ller: gnoc8 old_term: GSUS new_term: CLCEDSAM_C L782 - Counter: 11 128.212.27.6 old_poller: gnoc8 new_poller: gn +oc8 old_term: GSUS new_term: CLCEDSAM_C L782 - Counter: 12 128.212.28.74 old_poller: gnoc8 new_po +ller: gnoc8 old_term: GSUS new_term: CLCEDSAM_C L782 - Counter: 1 128.212.30.26 old_poller: gnoc8 new_po +ller: gnoc8 old_term: GSUS new_term: CLCEDSAM_E L782 - Counter: 2 128.212.64.26 old_poller: gnoc8 new_po +ller: gnoc8 old_term: GSUS new_term: CLCEDSAM_E


And here is the entirety of the file written out to with file handle GRPCHG:

L782    -

No character after the dash.

Why in the world do the files lack equivalent output? What is happening to the output that is not in the smaller file but seemingly should be? Am I missng something obvious?

Bewildered!!!

Tony (o2)

Replies are listed 'Best First'.
Re: Totally Befuddled With (Lack of) Text Output
by kyle (Abbot) on Sep 12, 2008 at 18:47 UTC

    I don't see the problem with the code you've posted, but it might help to check that open and close succeed.

    open(...) or die "Can't append '$dir/$file': $!"; # ... close(...) or die "Fail on close: $!";

    You can even check print the same way, if you're so inclined. Don't forget to include $! in the error message; it's the most informative part.

      Thank you and I'll try that check for succesful opening!

      Tony
        You might also want to check that the print is succeeding; one possibility would be a full disk or a quota error resulting in not writing the whole thing. Check the close, too; sometimes output errors are deferred to the close (when all the buffers are flushed).

        Also check the size of the file to make sure it's what you expect. It's possible for certain control characters to sneak into a file and make it look different on the screen than what's actually on the disk (like ^H).

        Hope this helps!

Re: Totally Befuddled With (Lack of) Text Output
by jethro (Monsignor) on Sep 12, 2008 at 18:54 UTC

    Are you sure you are looking into the right GRPCHG file? If you have quoted correctly, there seems to be a tab or a lot more spaces before the dash than in the print statement.

    You might check the time stamp of the GRPCHG file to see whether it was written at the same time as the TEST file. If the time stamp is wrong, you might have accessed an old file that was never deleted and a bug in the way the filename is constructed (check $homeDir if it really contains what you think it contains)

      Thanks! I have a clean_up script that removes all files. They are created on the same run, but it would be interesting to see if the time stamps have some disparity, indicating the incomplete one stopped being written out to.