string compare

M

missoula

$string1 eq $string2

will the above just compare the first letter of the 2 strings or
compare the whole string.
 
J

John Bokma

missoula said:
$string1 eq $string2

will the above just compare the first letter of the 2 strings or
compare the whole string.

If in doubt *always* check the documentation. Don't waste time of other
people.
 
S

Sherm Pendley

missoula said:
$string1 eq $string2

will the above just compare the first letter of the 2 strings or
compare the whole string.

The whole string. If you want to compare just the first character of two
strings, one way is to use eq and substr together:

if (substr($string1,0,1) eq substr($string2,0,1)) {
# First characters match.
}

sherm--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

perl compare function 2
C code String And Comparison 2
An issue with conditions! 0
Can someone please help me 1
Measuring a string of text 1
two attempts at DBI connect call 2
why does this happen? 53
strcpy/strcat 2

Members online

Forum statistics

Threads
473,780
Messages
2,569,614
Members
45,291
Latest member
BlockchainInvestorDatabse

Latest Threads

Top