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

Use of uninitialized value in string eq

by maxcross7 (Initiate)
on Sep 05, 2008 at 02:26 UTC ( #709165=perlquestion: print w/replies, xml ) Need Help??

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

Hello,

This script has worked forever until i moved to a new host. Now I am getting this error: "Use of uninitialized value in string eq"

It is complaining about this line:

if ($sitename eq $ENV{'id'} && ($visitor eq $ENV{'REMOTE_ADDR'}) || ($own eq $ENV{'REMOTE_ADDR'}))

and this one:

if ($sitename eq $ENV{'id'})

Let me know if you want me to post the entire script!?!
Any help is appreciated,
Thanks,
Max
  • Comment on Use of uninitialized value in string eq

Replies are listed 'Best First'.
Re: Use of uninitialized value in string eq
by dreadpiratepeter (Priest) on Sep 05, 2008 at 02:36 UTC
    The obvious answer is the $ENV{id} is no longer populated, the less obvious answer is that $sitename is no longer populated. Of course, one print statement will solve the mystery.


    -pete
    "Worry is like a rocking chair. It gives you something to do, but it doesn't get you anywhere."
Re: Use of uninitialized value in string eq
by bobf (Monsignor) on Sep 05, 2008 at 02:39 UTC

    I'd guess that either $sitename or $ENV{'id'} is undefined. You can check using defined:

    if( ! defined $sitename ) { # do something (initialize? skip 'eq' tests?) }

    Update: Oh, and the 'error' you cite isn't an error, it's a warning. See "Use of uninitialized value%s" in perldiag.

      Thank you for your quick response.
      Being a novice, I am not sure how to implement your responses.

      Where in the code should I insert this? Here is the code (required fields are normally populated):

      # This is the multicounter stats file $cntfile = ""; # To turn on logging $log = 1 else $log = 0 $log = 1; # If you want the counter output printed on your page $scrprint = 1 el +se 0 $scrprint = 1; # Location of your log file $logfile = ""; # Your own ip-address $own = ""; # -------------- Start program ----------------------------------- print "Content-type: text/html\n\n"; $date = localtime(time); open(INF,"$cntfile") || die "Can't open $cntfile to read: $! \n"; seek(INF,0,0); @data = <INF>; foreach $i (@data) { ($sitename,$counter,$ip_address) = split(/=/,$i); chop $ip_address; $sitename =~ s/ //g; $counter =~ s/ //g; $ip_address =~ s/ //g; $visitor = $ip_address; if ($sitename eq $ENV{'id'} && ($visitor eq $ENV{'REMOTE_ADDR'}) || ($ +own eq $ENV{'REMOTE_ADDR'})) { print $counter if ($scrprint eq "1"); exit; } else { if ($sitename eq $ENV{'id'}) { $counter++;<br> print $counter if ($scrprint eq "1"); open(ART,"$cntfile") || die "Can't open $cntfile to read: $! \n"; @data = <ART>; close(ART); open(ART,">$cntfile") || die "Can't open $cntfile to write: $! \n"; foreach $line (@data) { flock(ART,2); $line =~ s/$ENV{'id'} = [0-9]+ = [0-9]+.[0-9]+.[0-9]+.[0-9]+/$ENV{'id' +} = $counter = $ENV{'REMOTE_ADDR'}/g; print ART $line; } close(ART); if ($log eq "1") { open(OUTF,">>$logfile") || die "Can't open $logfile to write: $! \n"; print OUTF "$date | $ENV{'id'} | $counter | $ENV{'REMOTE_ADDR'} | $ENV +{'HTTP_REFERER'}\n"; close(OUTF); } } } }
        • Please use <CODE> tags. Instructions are in Writeup Formatting Tips
        • The diagnostic/error checking code for $sitename should be placed immediately after $sitename receives a value, via the "split" function.
        • $sitename receives its value from the INF ($cntfile) file. Looking at the contents of that file should help show what it would contain.
        • You should also check your $logfile -e it should contain the contents of $ENV{'id'}.

             Have you been high today? I see the nuns are gay! My brother yelled to me...I love you inside Ed - Benny Lava, by Buffalax

Re: Use of uninitialized value in string eq
by apl (Monsignor) on Sep 05, 2008 at 09:48 UTC
    On top of all the other advice, you should add use strict; use warnings;.
Re: Use of uninitialized value in string eq
by Sagacity (Monk) on Sep 06, 2008 at 06:23 UTC

    Try this little script on your new server to see if your 'id' is even available.

    #!/usr/bin/perl use CGI; $q = CGI->new(); print $q->header(); foreach $key (sort keys(%ENV)) { print "$key = $ENV{$key}<p>"; } 1;

    You should close the handle for INF after the @data = <INF>; line.

    Before you put yourself through hours of re-writing scripting, you may find that the environmental variable your looking for is named something else, or may not be turned on in the config file for the server.

    The Admin for the server should know.

    I have been through changing over to new servers in the past and un-wisely spent hours beating my head against the keyboard trying to trouble shoot a script only to find out that the new server didn't provide all the same environmental variables.

    By running the script provided, or something similar, you might be able to save yourself a few bruises.

    If the server is a shared hosting situation, the tech support should be able to turn on the variable for you, or may tell you to over-ride it in your own .htaccess file.

    If you need to do the latter, head over to This site or This site and learn all of the wonderful things you can do to control your hosted space with .htaccess

    It will save you hours of time in coding, and give you a better understanding of how to control and secure/protect your website from unwanted guest, and to better use the server resources to enhance your scripting.

    Best of Luck to you

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (4)
As of 2023-09-25 23:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?