Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Please help, my first Program not working :-(

Status
Not open for further replies.

ValerieLeeuwen

Programmer
Jul 19, 2004
2
NL
Hello val here, I wanted to start with my first perl program but it doesn't work :-(

Code:
#!/usr/bin/perl

my $valid_ip = 10.10.10.10;
my $ip_container = $ENV{REMOTE_ADDR};

if ($ip_container == $valid_ip)
 {
   print "Valid ip";
 }
else
 {
   print "Not a valid ip";
 }

think i'm doing it all wrong, could someone please explain or point me in the right direction? thanks Valerie
 
Hi,
try 'eq' instaed of '==', it seems to be considered as a string...
hope it helps...
Eve
 
@ Eve: Thanks i've cleaned up and fixed the code..

Code:
#!/usr/bin/perl

$good_ip = $ENV{REMOTE_ADDR};

if ($good_ip eq "10.10.10.10")
{
print "Content-type: text/html\n\n";
print <<ENDHTML;
<HTML>
<HEAD>
<TITLE>Perl Program 1</TITLE>
</HEAD>
<BODY>
<H2>Valid IP</H2>
</BODY>
</HTML>

ENDHTML

else
{
print "Content-type: text/html\n\n";
print <<ENDHTML;
<HTML>
<HEAD>
<TITLE>Perl Program 1</TITLE>
</HEAD>
<BODY>
<H2>Bad IP</H2>
</BODY>
</HTML>

ENDHTML
}

Val
 
A hint you will find often on this forum: Use strict and warnings. In other words, start each script is following:
Code:
#!/usr/bin/perl -w
use strict;

It will save you a lot of time finding obvious problems like typos in variables and all.
 
Hi Valerie

In at the deep end eh? Not even a "Hello World..." script?

How about something like this to reduce the code you type - if you are typing something more than once it can probably be shrunk down

Code:
[b]#!/usr/bin/perl[/b]

$ip = $ENV{REMOTE_ADDR};

if ($ip eq "10.0.0.1") {
  $validity = "Good I.P."
} else {
  $validity = "Bad I.P."
}

print <<ENDHTML;
Content-type: text/html\n\n
<HTML>
<HEAD>
<TITLE>Perl Program 1</TITLE>
</HEAD>
<BODY>
<H2>$validity</H2>
</BODY>
</HTML>
ENDHTML


Kind Regards
Duncan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top