in reply to What is wrong in this code?

Some additional observations:

  1. No need to declare $current_number before the loop. It’s a lexical variable which is not used outside of the loop, so declare it in the while condition:

    while (my $current_number = <STDIN>)
  2. No point in testing whether $current_number is defined: anything returned by <STDIN> will contain a newline (that’s why you chomp it!), so must be defined.

  3. You say the script works, but there is no elegant way for the user to break out of the loop. Give the user an option, for example “Q” for quit, and test for it after the chomp:

    last if $current_number eq 'Q';
  4. You should add print statements to prompt the user for input, otherwise how are they supposed to know what to do?

    print "Enter a number ('Q' to quit):\n";

    You will need to add this print statement twice, once immediately before the loop and once at the end.

Hope that helps,

Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,