in reply to Using a progress bar... having issues

First, add use strict; and use warnings; to the top of every script you write. It's a free error-checker and it's daft to ignore it. You have lots of uninitialized variables, you are not doing error checking on your function calls, and you are using barewords in the code. You need to fix all that.

I guess system(clear); and break; are supposed to stop the terminal going wonky; you probably need to use another Term::* module. Also 'clear' and 'break' cannot be unquoted:

Unquoted string "clear" may clash with future reserved word at 1137927 +.pl line 35. Bareword "break" not allowed while "strict subs" in use at 1137927.pl +line 57. Bareword "clear" not allowed while "strict subs" in use at 1137927.pl +line 35.

But the problem you originally asked about is caused by having copied code from the docs for Term::StatusBar:

sub doSomething { $status->setItems($_[0]); for (1..$_[0]){ sleep 1; $status->update; ## Will call $status->start() if needed } }

This is a subroutine that is called earlier in the example like this:

doSomething(20);

'20' is passed to the sub as an argument. Perl creates the special array @_ to hold the arguments passed to a sub. So in the example $_[0] is the first element in the array, i.e. the first argument passed, i.e. '20'. So the code says "sleep for one second and repeat once for each number between 1 and 20, then move on (and update the status bar status)".

Your code has no subroutine and there is no value in @_ or $_[0], so that's not going to work. if you had use warnings; Perl would have told you with the warning: Use of uninitialized value in foreach loop entry at foo.pl, line 52 ... and you could have been led to the problem.

I got rid of the for loop so that part of your code looks like:

if ($i % $j == 0) { $is_prime = 0; $status->setItems($i); sleep 1; }

This makes the bar advance, but there's more to do to get your program running right.

Advice: as a beginner, do one thing at a time. If you want to learn how to use a progress bar, create a small test script that does nothing else but that. When you copy examples to try out, copy the whole example and run it as is. Only once you have really "got it" should you combine that technique with others.

Hope this helps!

Update: added answer

The way forward always starts with a minimal test.