![]() ![]() String Manipulation For Programmers For a comparison of string function notation in different. ![]() See the chart below for the 5. Keywords: Len, size, count characters, chars, tool, on line tool. The smart match operator compares two items based on their type. If not, you could add the diagnostics pragma to get more information. In addtion to Sinan Ünür comprehensive listing of string comparison operators, Perl 5.10 adds the smart match operator. Perl has different operators (relational and equality operators)for comparing numbers and strings. That might be enough to send you off to the Perl syntax manual page, where you would learn that condition statements in Perl always require braces around the block. In order to compare for string equality, or if one string is alphabetically bigger than another, you can use the six string comparison operators. That makes it clear that the problem is the syntax around lines 6 and 7. Most who have been in contact with the command line in some form should be familiar with being used as a wildcard, and it has a similar use in Perl, matching any amount of the previous. Scalar found where operator expected at testif line 7, near ")Įxecution of testif aborted due to compilation errors. I think your str1 or str2 contains something like 'taste ' or so. I think your problem is that your variables don't contain what you think they do. Even if the 'if' condition is satisfied, it doesn't evaluate the 'then' block. So forget about CGI and web servers - just write a simple Perl program. First, eq is for comparing strings is for comparing numbers. I know you couldn't have known that initially, but a good way to investigate strange errors like this is to eliminate as many of the complications as possible. You have a good answer to your question, but it might be useful to point out how you could have investigated this yourself.įirstly, your original title for this question was "How do I compare two strings in a CGI page under Apache?" That title has been corrected because this problem has nothing to do with CGI or Apache, it's simply a misunderstanding about Perl syntax. Print STDOUT "Content-type: text/html\n\n" # Parse POST_STRING - NOTE: This CLEARS the post data # to a web page and use it to run a program on the webserver and # Test script to show how we can pass in the needed information The result of the string test ($stringtest) appears to be empty and I would not know how to test it if it wasn't. Other than setting a new variable equal to the result of an 'eq' operation, all the attempts result in the page blowing up. The following example demonstrates single and double-quoted strings. As you can see towards the bottom of the code below, I have tried 'eq', '=' and '='. A Perl string has a length that depends on the amount of memory in your system, which is theoretically unlimited. I am just trying to see if a variable is equal to 'Y'. If you want to compare things like text or source code, consisting of words or tokens and phrases and sentences, or expressions and statements, you. (obviously I am new to Perl and inherited this project). I must be doing something wrong but I cannot figure out what. I have googled until I ran out of options. ![]()
0 Comments
Leave a Reply. |