Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > What is this I don't even (control structure problems)

Reply
Thread Tools

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

 
 
Miro
Guest
Posts: n/a
 
      09-25-2011
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?
 
Reply With Quote
 
 
 
 
Bo Lindbergh
Guest
Posts: n/a
 
      09-25-2011
In article <(E-Mail Removed)>,
Miro <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
 
Jürgen Exner
Guest
Posts: n/a
 
      09-25-2011
Miro <(E-Mail Removed)> 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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 3 11-15-2009 06:51 AM
CPU Usage frequently 100% even though it seems not even close tototal memory Newcomer Computer Support 0 11-14-2009 11:21 PM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:30 AM
Why my working ps/2 mouse freezes and even don't even get recon.after reboot ? demi General Computer Support 0 08-03-2007 05:28 AM
Even older fart, even newer newbie Stan Goodman Java 11 07-04-2003 07:32 AM



Advertisments