simple string comparing

Discussion in 'Perl' started by vertigo, Apr 20, 2004.

  1. vertigo

    vertigo Guest

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


    Thanx
    Michal
    vertigo, Apr 20, 2004
    #1
    1. Advertising

  2. vertigo wrote:
    > 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ürgen Exner, Apr 20, 2004
    #2
    1. Advertising

  3. vertigo

    Jim Gibson Guest

    In article <c63rbq$okv$>, vertigo
    <> wrote:

    > 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.
    Jim Gibson, Apr 21, 2004
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. - Steve -

    Comparing String with ASP.net

    - Steve -, Feb 27, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    3,911
    Kevin Spencer
    Feb 27, 2004
  2. .Net Sports
    Replies:
    1
    Views:
    2,638
    intrader
    Jun 25, 2005
  3. HS1
    Replies:
    2
    Views:
    356
    John McGrath
    Nov 29, 2004
  4. ankur
    Replies:
    1
    Views:
    12,665
    Jan =?UTF-8?B?VGhvbcOk?=
    Aug 27, 2007
  5. Owner
    Replies:
    2
    Views:
    266
    Owner
    Feb 18, 2011
Loading...

Share This Page