simple string comparing

V

vertigo

Hello
How can i check if $mystring is exactly equal to "."
Where "." means one character (comma) ?


Thanx
Michal
 
J

Jürgen Exner

vertigo said:
How can i check if $mystring is exactly equal to "."
Where "." means one character (comma) ?

Did you check "perldoc perlop", section "Equality Operators"?

jue
 
J

Jim Gibson

vertigo said:
Hello
How can i check if $mystring is exactly equal to "."
Where "." means one character (comma) ?

If you only want a comma, use

if( $mystring eq ',' ) {
# do something if it's a comma
}

If you want any one-character string:

if( $mystring =~ m/^.$/ ) {
# do something if it's one character
}

or even better

if( length($mystring) == 1 ) {
# it's one character
}

Note the different comparison operators:

eq for string compare
=~ for pattern match
== for numerical compare
Thanx
Michal

This newsgroup is defunct. Try comp.lang.perl.misc in the future.
 

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

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top