compare strings

Discussion in 'Perl Misc' started by DirkN, Oct 16, 2008.

  1. DirkN

    DirkN Guest

    hi

    I am comparing two string arrays, yet I get this warning:
    Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
    line 22.

    this is the code
    if ("$user[$i]"=="$uniq[$j]") {..}

    is there a different operator when comparing strings?

    Dirk
     
    DirkN, Oct 16, 2008
    #1
    1. Advertising

  2. DirkN

    cartercc Guest

    On Oct 16, 11:52 am, DirkN <> wrote:
    > hi
    >
    > I am comparing two string arrays, yet I get this warning:
    > Argument "sas     " isn't numeric in numeric eq (==) at ./alljobs_read
    > line 22.
    >
    > this is the code
    > if ("$user[$i]"=="$uniq[$j]") {..}
    >
    > is there a different operator when comparing strings?
    >
    > Dirk


    eq
     
    cartercc, Oct 16, 2008
    #2
    1. Advertising

  3. DirkN <> wrote:

    > hi
    >
    > I am comparing two string arrays, yet I get this warning:
    > Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
    > line 22.
    >
    > this is the code
    > if ("$user[$i]"=="$uniq[$j]") {..}
    >
    > is there a different operator when comparing strings?
    >
    > Dirk


    if ($user[$i] eq $uniq[$j]) {..}

    --
    [pl>en Andrew] Andrzej Adam Filip : :
    Why won't you let me kiss you goodnight? Is it something I said?
    -- Tom Ryan
     
    Andrzej Adam Filip, Oct 16, 2008
    #3
  4. DirkN

    Tim Greer Guest

    DirkN wrote:

    > hi
    >
    > I am comparing two string arrays, yet I get this warning:
    > Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
    > line 22.
    >
    > this is the code
    > if ("$user[$i]"=="$uniq[$j]") {..}
    >
    > is there a different operator when comparing strings?
    >
    > Dirk


    == is only a numeric check and can have unexpected results unless you
    know what it does and why. Use eq instead for non numeric checks.
    --
    Tim Greer, CEO/Founder/CTO, BurlyHost.com, Inc.
    Shared Hosting, Reseller Hosting, Dedicated & Semi-Dedicated servers
    and Custom Hosting. 24/7 support, 30 day guarantee, secure servers.
    Industry's most experienced staff! -- Web Hosting With Muscle!
     
    Tim Greer, Oct 16, 2008
    #4
  5. DirkN <> wrote:
    > hi
    >
    > I am comparing two string arrays, yet I get this warning:
    > Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
    > line 22.
    >
    > this is the code
    > if ("$user[$i]"=="$uniq[$j]") {..}
    >
    > is there a different operator when comparing strings?



    Yes.


    --
    Tad McClellan
    email: perl -le "print scalar reverse qq/moc.noitatibaher\100cmdat/"
     
    Tad J McClellan, Oct 16, 2008
    #5
  6. DirkN

    John Bokma Guest

    DirkN <> wrote:

    > hi
    >
    > I am comparing two string arrays, yet I get this warning:
    > Argument "sas " isn't numeric in numeric eq (==) at ./alljobs_read
    > line 22.
    >
    > this is the code
    > if ("$user[$i]"=="$uniq[$j]") {..}


    Read

    perldoc -q always

    (What's wrong with always quoting "$vars")

    > is there a different operator when comparing strings?


    Yes. I recommend to study

    perldoc perlop

    (section Relational Operators)

    --
    John http://johnbokma.com/ - Hacking & Hiking in Mexico

    Perl help in exchange for a gift:
    http://johnbokma.com/perl/help-in-exchange-for-a-gift.html
     
    John Bokma, Oct 16, 2008
    #6
    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. Thomas Reinemann

    How to compare strings

    Thomas Reinemann, May 27, 2004, in forum: VHDL
    Replies:
    0
    Views:
    630
    Thomas Reinemann
    May 27, 2004
  2. =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=

    Newbie: How to compare strings?

    =?Utf-8?B?Y2hhcmxpZXdlc3Q=?=, Aug 16, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    373
    Brock Allen
    Aug 16, 2005
  3. Replies:
    0
    Views:
    442
  4. al

    Compare strings

    al, Dec 21, 2003, in forum: C++
    Replies:
    1
    Views:
    533
    Cy Edmunds
    Dec 21, 2003
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    767
    Malcolm
    Jun 24, 2006
Loading...

Share This Page