in reply to loop problem

Where is your loop?


With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority". The enemy of (IT) success is complexity.
In the absence of evidence, opinion is indistinguishable from prejudice. Suck that fhit

Replies are listed 'Best First'.
Re^2: loop problem
by WisDomSeeKer34 (Sexton) on Jun 12, 2018 at 16:55 UTC
    There is no loop in this code. I tried it with a submodule. Like this:
    #!/usr/bin/env perl # use strict; use warnings; use utf8; use feature "say"; use Math::Trig; sub intro { say "What is the radius?"; our $radius= <STDIN>; chomp ($radius); our $a = 2*pi; our $c = $radius * $a } intro(); if ($radius==0) { say "circumference= ", $radius; } elsif ($radius<0) { say "Radius should be greater than 0"; intro(); } else { say "circumference= ", $c }

    But you have to switch off the strict command to make it work. And then it still doesn't work like I want it to.

    How to create the loop I want?

      I tried it with a submodule.

      In this context, the proper word for "submodule" is "subroutine."


      Give a man a fish:  <%-{-{-{-<

      What error does strict throw? Works fine for me as-is on 5.26.1.

      Anyway, here's an example of how to get what you want:

      my $radius = -1; until ($radius >= 0){ say "What is the radius?"; $radius= <STDIN>; chomp ($radius); say "radius must be >= 0. Try again..."; }

        Regarding your question: if I run the program with the submodule with strict, I get this output:

        Variable "$radius" is not imported at circum1.pl line 19. Variable "$radius" is not imported at circum1.pl line 20. Variable "$radius" is not imported at circum1.pl line 23. Variable "$c" is not imported at circum1.pl line 30. Global symbol "$radius" requires explicit package name (did you forget + to declare "my $radius"?) at circum1.pl line 19. Global symbol "$radius" requires explicit package name (did you forget + to declare "my $radius"?) at circum1.pl line 20. Global symbol "$radius" requires explicit package name (did you forget + to declare "my $radius"?) at circum1.pl line 23. Global symbol "$c" requires explicit package name (did you forget to d +eclare "my $c"?) at circum1.pl line 30. Execution of circum1.pl aborted due to compilation errors.
        And thank you for answering my question.