Htorne has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks

Im a all new to Perl, and have dreams of one day reaching the Perl Niavarna - but before that I need studdy for a few years.

Thus my first question.

This is my project. #Write a program that computes the circumference of a circle with a radius of 12.5
#Circumference is 2(pi) times the radius (approximately 2 times 2.141592654).
#The answer you get should be about 78.5

This is how I solved it
$pi = 3,141592654; $resultat = 2*$pi*12,5; print "$resultat";
quite simpel - but when I run this code in Komodo Personal 4.0 I get the following messages:

-----------------------------------------------------
Useless use of a constant in void context at
C:\Users\Max\Desktop\Perl Arbejde\opgave1.pl line 6.
72
Useless use of a constant in void context at
C:\Users\Max\Desktop\Perl Arbejde\opgave1.pl line 7.
-----------------------------------------------------
It says that I got a useless use of a constant in void
context ? I can't find out if I can boil down my code

anymore ? It is really anoying that it also gives the
result 72 when that not the corect result. Its really strange.

Many thanks for reaching this point in my question.

Htorne

Replies are listed 'Best First'.
Re: Komodo 4.0 Bug ? Unlikely but....
by davorg (Chancellor) on Jan 23, 2007 at 11:06 UTC

    The bug is in the code, not the tool :)

    $pi = 3,141592654;

    I think you mean:

    $pi = 3.141592654;

    You make the same error on the next line when you use 12,5 instead of 12.5.

    Perl (like all other programming languages that I've used) uses a decimal point to denote the start of the fractional portion of a number. This sometimes confuses programmers who come from cultures that use a comma for the same thing.

    If you get an error message from Perl that you don't understand, then you can add use diagnostics to your program and Perl will give you a longer explanation of the error.

    --
    <http://dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      Oh my God, thanks - guess this is only something that I do once. :) but yep, im from denmark where we use ., differently :) thanks
        ;-)

        For more accurate values of PI see Golf -- compute PI :-D

        --shmem

        _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                      /\_¯/(q    /
        ----------------------------  \__(m.====·.(_("always off the crowd"))."·
        ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}
        I want to give some additional information if you want to round off your result you can use
        use Math::Round; $data=nearest (.1,$data)
        With use of this class and this function you can round off upto desired decimal number,where $data is some number we are getting to which we want to round off and Your problem is solved i think so ,it is because you are using "," instead of "."
        I think it will help you in future.
Re: Komodo 4.0 Bug ? Unlikely but....
by jonadab (Parson) on Jan 23, 2007 at 14:12 UTC
    $pi = 3,141592654;

    You know, I am really starting to think perl should issue a specific warning on use of the scalar comma operator. It's almost never intentional and a regular source of newbie problems.


    Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.
      You mean like
      C:\>perl -e"$_ = 2,3" C:\>perl -we"$_ = 2,3" Useless use of a constant in void context at -e line 1.

        No, I don't mean "useless use of foo in void context". I mean something rather more specific, along the lines of "comma operator encountered in scalar context; throwing away whatever precedes it".

        Bear in mind, sometimes the thing that's thrown away isn't a constant. It can be (the return value of) a function call, for instance, and where is the "useless use of foo" warning then?

        I realize there are probably rare situations in which an advanced programmer uses the scalar comma deliberately, but that's why recent versions of perl have added the ability to pragmatically set aside specific types of warnings within a lexical block. In the overwhelming majority of cases, the scalar comma is introduced by programmer error, and the warning would be beneficial.


        Sanity? Oh, yeah, I've got all kinds of sanity. In fact, I've developed whole new kinds of sanity. You can just call me "Mister Sanity". Why, I've got so much sanity it's driving me crazy.
Re: Komodo 4.0 Bug ? Unlikely but....
by geekphilosopher (Friar) on Jan 23, 2007 at 22:08 UTC
    You should keep in mind that Komodo 4.0 is still in beta (though a pretty stable beta - it's worked fine for me). If you're looking for a release version, try out 3.5.
      I just finished talking to the guys at ActiveState, and it turns out that Komodo 4.0 was released just this afternoon. Also, they've got a new version of their product in Beta, basically a "Komodo Lite" called Komodo Edit.