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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

What do these CGI Char mean?

Status
Not open for further replies.

salc76

Technical User
Feb 21, 2007
21
CA
Can someone explain to me what some characters represent in the following lines of cgi code?

- eq?
- ""?
- !~?
- &&?
- ne?

if($name eq "" || $staddress eq "" || $city eq "" || $province eq "" || $postalcode eq "" || $phonenumber eq "" || $email eq "") {
&error();
}
elsif($name ne "" && $name !~ m/^[A-Za-z][A-Za-z\s]*/) {
&error();
}
elsif($staddress ne "" && $staddress !~ m/^[0-9A-Za-z\.\#][0-9A-Za-z\.\#]*/) {
&error();

 
eq - "equal" (string operator)
"" - an empty string
!~ - "not equal" (regexp binding operator)
&& - "and" (logical "and" operator)
ne - "not equal" (string operator)


thats not CGI code, it's perl code.


------------------------------------------
- Kevin, perl coder unexceptional! [wiggle]
 
|| == shortcircuit or, or leftwise or if this 'or' operator finds a true case, it doesn't bother evaluating the rest of the cases for true.
likewise && in the event of a false case, it doesn't bother evaluating the rest of the cases for true.
Code:
if (isiteven(1) || isiteven(2) || isiteven (3) ) {
  print "  End test 1\n";
} else {
  print "  Test Failed\n";
}

if (isiteven(1) && isiteven(2) && isiteven (3) ) {
  print "  End test 2\n";
} else {
  print "  Test Failed\n";
}
if (isiteven(2) && isiteven(4) && isiteven (6) ) {
  print "  End test 3\n";
} else {
  print "  Test Failed\n";
}

sub isiteven {
  ($var)=@_;
  if ($var%2==0) {
    print "$var is even\n";
    return 1;
  } else {
    print "$var is false\n";
    return 0;
  }
}
returns
Code:
1 is false
2 is even
  End test 1
1 is false
  Test Failed
2 is even
4 is even
6 is even
  End test 3
It's a form of code efficiency in that the logical and and or operators will evaluate every case.

Paul
------------------------------------
Spend an hour a week on CPAN, helps cure all known programming ailments ;-)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top