On 11-08-22 05:03 AM, Shlomi Fish wrote:
It's a good idea to always use "last LABEL;" instead of "last;" (as well as
"next LABEL;" etc. in case more loops are added in between.

Good idea but try to choose meaningful names. Also, the else clause is not needed.

[CODE]
use strict;
use warnings;

my @numbers = ();

print "Enter numbers, one per line:\n";

INPUT_NUMBERS_LOOP:
while (1) { # do forever

    # get a line from STDIN
    chomp( my $number = <STDIN> );

    # validate if a number
    if ( $number =~ /\D/ ) {
        print "$number is not a numeric value.\n";
        last INPUT_NUMBERS_LOOP;
    }

    # don't store empty lines
    if( length( $number ) > 0 ){
        push @numbers, $number;
    }

}
[/CODE]


--
Just my 0.00000002 million dollars worth,
  Shawn

Confusion is the first step of understanding.

Programming is as much about organization and communication
as it is about coding.

The secret to great software:  Fail early & often.

Eliminate software piracy:  use only FLOSS.

"Make something worthwhile."  -- Dear Hunter

--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/


Reply via email to