Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Refusal to Run

by Andrew_Levenson (Hermit)
on Aug 02, 2006 at 20:16 UTC ( #565316=perlquestion: print w/replies, xml ) Need Help??

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

I have some code, a simple test program to get me re-acquainted with the syntax and all after a break.
However, my computer absolutely refuses to run it. My command prompt locks up. It's nothing tasking or anything, and it won't tell me what's wrong. Any ideas?
Edit: Fixed using ideas from the CB, and it still won't start. :(
use strict; use warnings; my ($i, $j, $x, $tot); my @exes; print "Please enter for how many values of x you will be finding the Standard Deviation.\n"; do {chomp($i=<>); print "\nPlease only use numbers.\n" if $i=~m/\D/;} until($i!~m/\D/ and $i=~m/\d/); print "\nPlease input the values of x, one at a time.\n"; for $j(1..$i){ do {chomp($x=<>); print "\nPlease only use numbers.\n" if $x=~m/\D +/;} until($x!~m/\D/ and $x=~m/\d/); push @exes, $x;} undef $x; for(@exes){ $x=$x+$_;} my $ave=$x/$i; for(@exes){ $tot=$tot+(($_-$ave)^2);} my $deviation=sqrt($tot/$i); print "\nThe Standard Deviation of that set of numbers is $deviation.\ +n";


Thanks.

Replies are listed 'Best First'.
Re: Refusal to Run
by jeffa (Bishop) on Aug 02, 2006 at 21:30 UTC

    Wow, that is one messy chunk of code you have. A long time ago, Ovid wrote this gem: Clean your room. Please consider using tools such as perltidy to make your code more readable ... for others. Here is what your code looks like after i ran it through perltidy (i'm using the code you orginally posted as saved by betterworld):

    I hope you will agree that posting code that is easier to read by others will help you receive better answers, faster (not that the fast answers you have already received are bad). Help us help you.

    jeffa

    L-LL-L--L-LL-L--L-LL-L--
    -R--R-RR-R--R-RR-R--R-RR
    B--B--B--B--B--B--B--B--
    H---H---H---H---H---H---
    (the triplet paradiddle with high-hat)
    
      Wow, thanks, that IS a lot more readable.
      I'll fix mine up and re-post it tonight when I get the chance.

      And thanks for being congenial about it.
Re: Refusal to Run
by gawatkins (Monsignor) on Aug 02, 2006 at 20:50 UTC

    Once the until statements are fixed, and a my $i; is added, you have a divide by zero in my $deviation=sqrt($tot/$i);. How are you executing this, if it is a *nix you need a #! line, if win32, ther could be a problem with your install.

    Thank you
    Greg W

    UPDATE: removed the my $i, the line  my $deviation=sqrt($tot/$n); changed to my $deviation=sqrt($tot/$i); from the first time I downloaded until I looked again.

    UPDATE: fixed the formating errors of the firs update...

Re: Refusal to Run
by betterworld (Curate) on Aug 02, 2006 at 20:32 UTC
    it won't tell me what's wrong
    Interestingly, when I tried to run it, it did.
    syntax error at a.pl line 8, near ");" syntax error at a.pl line 12, near ");" Global symbol "$n" requires explicit package name at a.pl line 20. Execution of a.pl aborted due to compilation errors.
    Maybe you should use do {stuff;} until (condition()); rather than {stuff;} until (condition());

    Since the OP has updated his code, this post has become futile. For reference, here is the original code:
Re: Refusal to Run
by Popcorn Dave (Abbot) on Aug 03, 2006 at 03:55 UTC
    Have you tried stepping through it with a debugger to see exactly where it's hanging? My debugger of choice is ptkdb but YMMV.

    Revolution. Today, 3 O'Clock. Meet behind the monkey bars.
Re: Refusal to Run
by bart (Canon) on Aug 03, 2006 at 11:35 UTC
    I'm sorry to spoil your party, but your script works for me. Like I already said in the Chatterbox, it probably is just waiting for you to enter data. Even if you don't see any prompts, try entering numbers followed by return at the console, and see if it responds to it.

    If it does, and I bet it will, it would be a good idea to set

    $| = 1;
    near the top of your script.

    Furthermore, your gives a few warnings, caused by

    undef $x; for(@exes){ $x=$x+$_; }
    which can be fixed by eiter setting $x to 0 instead, or by doing
    undef $x; for(@exes){ $x += $_; }
    which does the same thing, but is shorter, and doesn't warn if $x is undef.

    Worse, there's a nasty error, that makes your script output a wrong result: the power operator in Perl is **, not ^, which does XOR. See perlop. So:

    for(@exes){ $tot += ($_-$ave)**2; }
      It is not waiting for input, I thought of that.
      It just sits there. If it runs for everyone else, I figure it's my machine, not the script.

      And thanks for reminding me about the exponentation bit, I completely forgot.
Re: Refusal to Run
by runrig (Abbot) on Aug 02, 2006 at 20:24 UTC
    Suffering from Buffering maybe?

    Update: Nevermind...obviously this is not the problem here (and obviously I was not intimately familiar with the default STDIO buffering behaviour, and I haven't read that link myself for a while).

      Why would that be? What evidence is there that the OP has changed the default STDIO buffering in such a way that this would be a problem?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://565316]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (5)
As of 2022-10-07 08:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My preferred way to holiday/vacation is:











    Results (29 votes). Check out past polls.

    Notices?