You need to use == for comparison (that is two equal signs ), you are just using one and that means assignment.
For example, my $value = 100; print "value = $value\n"; if( $value == 300 ) { print "value = $value\n"; } elsif( $value = 200 ) { print "value = $value\n"; } will print out value = 100 value = 200 because an assignment to a non zero value is true. HTH, Tanton ----- Original Message ----- From: "Chris" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, February 14, 2002 12:11 PM Subject: Re: Urgent - Getting the left most 3 characters from a string... > Brett W. McCoy wrote: > > On Thu, 14 Feb 2002, Chris wrote: > > > > > >>if left($result,3) = "500" Then > >> Do whatever > >>Else > >> Blah Blah Blah > >>End If > >> > >>In Perl I want to do: > >> > >>if (left($result), 3) = 500 { > >> Do whatever; > >>} else { > >> Blah Blah Blah; > >>} > >> > >>How can I do the left in Perl???? > >> > > > > if(substr($result, 0, 3) == 500) { > > > > perldoc -f substr > > > > -- Brett > > http://www.chapelperilous.net/ > > ------------------------------------------------------------------------ > > Who made the world I cannot tell; > > 'Tis made, and here am I in hell. > > My hand, though now my knuckles bleed, > > I never soiled with such a deed. > > -- A.E. Housman > > > > > > Thanks! > > Had to revert back to the original, as time was running out, and this > was MC! (Mission Critical).. > > Here is what is failing...: > (Its running on Win32, btw) > > $filename = "c:\pingtest.txt"; > $hostname = "http://thisisgoingtofail.com"; > @access; > > sub access { > > $result = ""; > open (DUMPFILE,">>$filename"); > print DUMPFILE > "******************************************************************** \n"; > print DUMPFILE "*\n"; > print DUMPFILE "* $hostname\n"; > print DUMPFILE "*\n"; > $result = substr(getprint("$hostname"),0 ,3); > print "Results - $result\n"; > # Note - the above shows the code to be 500!!! > my $newresult = $result; > print "New Results - $$newresult\n"; > my $resultcode; > print "Result Code - $$resultcode;\n"; > if ($newresult = 200) { > $resultcode = "Code 200 - Access successful\n"; > } elsif ($newresult = 400) { > $resultcode = "Code 400 - Bad Request\n"; > } elsif ($newresult = 403) { > $resultcode = "Code 403 - Forbidden\n"; > } elsif ($newresult = 404) { > $resultcode = "Code 404 - Not Found\n"; > } elsif ($newresult = 405) { > $resultcode = "Code 405 - Method Not Allowed\n"; > } elsif ($newresult = 406) { > $resultcode = "Code 406 - Not Acceptable\n"; > } elsif ($newresult = 407) { > $resultcode = "Code 407 - Proxy Authentication Required\n"; > } elsif ($newresult = 408) { > $resultcode = "Code 408 - Request Timeout\n"; > } elsif ($newresult = 409) { > $resultcode = "Code 409 - Conflict\n"; > } elsif ($newresult = 410) { > $resultcode = "Code 410 - Gone\n"; > } elsif ($newresult = 500) { > $resultcode = "Code 500 - Internal Server Error\n"; > } elsif ($newresult = 501) { > $resultcode = "Code 501 - Not Implemented\n"; > } elsif ($newresult = 502) { > $resultcode = "Code 502 - Bad Gateway\n"; > } elsif ($newresult = 503) { > $resultcode = "Code 503 - Service Unavailable\n"; > } elsif ($newresult = 504) { > $resultcode = "Code 504 - Gateway Timeout\n"; > } elsif ($newresult = 505) { > $resultcode = "Code 505 - HTTP Version Not Supported\n"; > } else { > $resultcode = "Unknown error...\n"; > } > print "\nNew Results Code - $resultcode\nNew Results - > $newresult\nOld Results - $result"; > print DUMPFILE "* $result\n"; > print DUMPFILE "*\n"; > close (DUMPFILE); > > } > > > Here are the results... > > (I am not sure why that '1'prints out, but it is never to the file...) > > C:\scripts\perl>ping.pl > 1500 Can't connect to www.thiswillfail.com:80 (Bad hostname > 'www.thiswillfail.com') > <URL:http://www.thiswillfail.com> > Results - 500 > New Results - > Result Code - ; > > New Results Code - Code 200 - Access successful > > New Results - 200 > Old Results - 500 > C:\scripts\perl> > > Any advice is greatly appreciated.. > > And the substr was EXTREMELY helpful! :) > > > -- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]