Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Error/Warnings

by pdaggett (Initiate)
on Feb 24, 2001 at 01:04 UTC ( [id://60553]=perlquestion: print w/replies, xml ) Need Help??

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

Edited by Corion: Added <CODE> tags.

Why would this error be showing in the error log on this call
I am new so please forgive my ignorance. How would I write this to not show any warnings in the Log? Use of uninitialized value at /mnt/www/vdir/cgi-bin/rank/serrors.cgi line 12, chunk 1.


#!/usr/bin/perl -w use CGI qw(:standard); use strict; print header; print start_html("ERROR LOG"); my $logfile = "errort.log"; open(FILEHANDLE ,"$logfile"); my $temp; while (<FILEHANDLE>) { $temp = $temp . $_ . "<br>"; } print "$temp";

Replies are listed 'Best First'.
Re: Error/Warnings
by SparkeyG (Curate) on Feb 24, 2001 at 01:23 UTC
    My suggestion, such as it is, would be first to initialize your $temp var ala:
    my $temp = "";

    Second, I would suggest within your while loop:
    while ( <> ) { $temp .= $_."\n"; }

    --SparkyG UPDATE
    Added <> to the while loop condition. I was just furthering someone else's errors. --SparkeyG
Re: Error/Warnings
by dws (Chancellor) on Feb 24, 2001 at 01:30 UTC
    Assuming that the lines in errort.log already have newelines at the end, and assuming you want to print the entire file, you can further simplify this as:
    ... open(LOG, "<$logfile") or die "$logfile: $!"; print "<pre>"; print <LOG>; print "</pre>\n"; close(LOG);

    Update: Reasonable people are disagreeing on how to interpret your question. Please clarify: Are the warnings you want to avoid seeing 1) produced by the script, or 2) in the logfile?

Re: Error/Warnings
by MeowChow (Vicar) on Feb 24, 2001 at 02:34 UTC
    I believe your warning is coming from the uninitialized $_ that you are concatenating, but that is really the least of your worries. The following section runs an infinite loop:
    while () { $temp = $temp . $_ . " "; }
    I think you meant:
    while (<FILEHANDLE>) { $temp .= $_; }
    update: forgot to put parens around the while
       MeowChow                                   
                   s aamecha.s a..a\u$&owag.print
Re: Error/Warnings
by enoch (Chaplain) on Feb 24, 2001 at 01:36 UTC
    You are using $temp before it is initialized. That is, $temp is concatenated with $_ and assigned to $temp. However, at first run, $temp is uninitialized.
    Try a $temp = ""; like SparkyG stated.

    Jeremy
      What about the line:
      my $temp;
      ???

      Update: the noted line above does indeed cover initialization with -w.

      I just cut'n'pasted the code above from pdaggett and short of having to add a filehandle in the while control, it worked on one of my files.

      Now, we just need some clarification on the sentence "How would I write this to not show warnings in the Log?"

      ALL HAIL BRAK!!!

Re: Error/Warnings
by PsychoSpunk (Hermit) on Feb 24, 2001 at 01:26 UTC
    I dunno. What does your warning message look like?

    I'd do something like this (presuming my warning messages had this format):

    while (<>) { if ($_ !~ /^Warning:/) { $temp .= $_; } }

    HTH.

    ALL HAIL BRAK!!!

A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://60553]
Approved by root
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found