What is this I don't even (control structure problems)

Discussion in 'Perl Misc' started by Miro, Sep 25, 2011.

  1. Miro

    Miro Guest

    I've been using Perl for about 6 months now, and I've never had issues
    with this before, but when I run this following code snippet...

    my $variable = "f";
    if ($variable == "d"){
    print ($variable . " is d\n")
    }elsif ($variable == "f"){
    print ($variable ." is f\n")
    }

    ....it says "f is d"
    What am I doing wrong?
    Miro, Sep 25, 2011
    #1
    1. Advertising

  2. Miro

    Bo Lindbergh Guest

    In article <>,
    Miro <> wrote:
    > What am I doing wrong?


    You're not using the strict and warnings pragmas. Put these two lines
    at the top of your program and see if you get any interesting diagnostic
    messages:

    use strict;
    use warnings;


    /Bo Lindbergh
    Bo Lindbergh, Sep 25, 2011
    #2
    1. Advertising

  3. Miro <> wrote:
    >I've been using Perl for about 6 months now, and I've never had issues
    >with this before, but when I run this following code snippet...
    >
    >my $variable = "f";
    >if ($variable == "d"){


    The numerical value of the content of $variable is 0. The numerical
    value of "d" is also 0. Therefore the result of the numerical equality
    test == is true, therefore

    > print ($variable . " is d\n")


    this path is executed and "f is d\n" is printed.

    >}elsif ($variable == "f"){
    > print ($variable ." is f\n")
    >}
    >
    >...it says "f is d"
    >What am I doing wrong?


    Maybe you meant to use string comparison "eq" instead of numerical
    comparison "=="?

    jue
    Jürgen Exner, Sep 26, 2011
    #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. Stan Goodman

    Even older fart, even newer newbie

    Stan Goodman, Jul 3, 2003, in forum: Java
    Replies:
    11
    Views:
    678
    Stan Goodman
    Jul 4, 2003
  2. Replies:
    0
    Views:
    242
  3. TJ
    Replies:
    4
    Views:
    351
    Steven Cheng[MSFT]
    Apr 7, 2006
  4. den 2005
    Replies:
    0
    Views:
    109
    den 2005
    Nov 21, 2006
  5. Replies:
    6
    Views:
    116
Loading...

Share This Page