I usually do this:
my $IP = ENV('REMOTE_ADDR', '0.0.0.0'); print $IP; exit; ################### # This function returns an environment variable named in the # first argument. If the environment variable doesn't exist, # then DEFAULT is returned. However, if a third argument is # given, then that will be returned in every case. # The third argument is used for tweaking and testing purposes. # # Usage: VALUE = ENV( NAME, [DEFAULT, [OVERRIDE]] ) # sub ENV { return '' unless @_; # No arguments at all? my $NAME = shift; # Get NAME my $DEFAULT = @_ ? shift : ''; # Get DEFAULT value return shift if @_; # OVERRIDE? return $DEFAULT unless defined $NAME; # NAME undefined? return $DEFAULT unless $NAME; # NAME is blank? if (exists($ENV{$NAME})) { return Trim($ENV{$NAME}); } return $DEFAULT; } ################### # # This function removes whitespace before and after STRING # and returns a new string. # # Usage: STRING = Trim(STRING) # sub Trim { return '' unless @_; my $T = shift; return '' unless defined $T; return '' unless length($T); my $s = -1; # start ptr my $e = 0; # end ptr for (my $i = 0; $i < length($T); $i++) { if (vec($T, $i, 8) > 32) { if ($s < 0) { $s = $i; } $e = $i; } } return substr($T, $s, $e - $s + 1); }
This means, even if REMOTE_ADDR is undefined for whatever reason, I get a string in $IP which is going to be 0.0.0.0. And then I know that it's because it was undefined!

In reply to Re: $ENV{REMOTE_ADDR} problem by harangzsolt33
in thread $ENV{REMOTE_ADDR} problem by bigup401

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.