0

i wrote this tiny code on gedit and ran it :-

#/usr/bin/perl
print "Enter the radius of circle: \n";
$radius = <>;
chomp $radius;
print "radius is: $radius\n";
$circumference = (2*3.141592654) * $radius;
print "Circumference of circle with radius : $radius = $circumference\n";

Runs fine using command line.Ran the same code on Komodo Edit: facing an issue i expect first line as output as :- Enter the radius of circle: whearas it waits on the screen i.e waiting for an input and after that runs everything in sequence -- can someone tell me why it runs fine with command line but not Komodo?


output after changing #/usr/bin/perl to #!/usr/bin/perl:- also had to declare my $radius and my $circumference ----------------------------------------------------------

12 # same i had to enter 12
Enter the radius of circle: 
radius is: 12
Circumference of circle with radius : 12 = 75.398223696
rgolwalkar
  • 237
  • 1
  • 3
  • 10
  • 1
    correct the first line first, it should be '#!/usr/bin/perl' – Space Apr 23 '10 at 06:24
  • output after changing as you mentioned:- also had to declare my $radius and my $circumference ---------------------------------------------------------- 12 # same i had to enter 12 Enter the radius of circle: radius is: 12 Circumference of circle with radius : 12 = 75.398223696 – rgolwalkar Apr 23 '10 at 06:39
  • this is correct, what is the error you are facing with Komodo edit. – Space Apr 23 '10 at 06:55
  • You appear to be a new Perl programmer. A quick tip: *always* start every file with `use strict; use warnings;` -- it will save you lots of pain. – Ether Apr 23 '10 at 14:48

2 Answers2

0

I have tested your script using Komodo edit and it works fine other then below few corrections.

#!/usr/bin/perl -w
use strict;

print "Enter the radius of circle: \n";
my $radius = <>;
chomp $radius;
print "radius is: $radius\n";
my $circumference = (2*3.141592654) * $radius;
print "Circumference of circle with radius : $radius = $circumference\n";

Output in Komodo

Enter the radius of circle: 
5
radius is: 5
Circumference of circle with radius : 5 = 31.41592654
Space
  • 7,049
  • 6
  • 49
  • 68
  • @ Ether - yes i am new to perl and i will keep your advice in mind thanks @Octopus - Thanks for checking it Thanks a lot all - this kind of help gives a beginner the confidence that someone can help :) – rgolwalkar Apr 24 '10 at 06:24
  • Its funny but it doesn't work in Komodo - it works fine through command line -- it just waits for the input for some reason - may its about some setting in Komodo. :) – rgolwalkar Apr 26 '10 at 22:40
0

While 'use strict' and a correctly spelled shebang line are always good things, neither is the actual cause. When you run an interactive program in a non-command-line environment, you should usually turn off I/O buffering. In Perl you should put this line at the top of your code:

$| = 1;
Eric
  • 2,115
  • 2
  • 20
  • 29