Hi all, This page accepts a series of numbers, separated by spaces, and gives the values listed bellow.
I'm getting the following error, but don't see why. Can anyone spot my error? Please, enter numbers separated by spaces only!: Bad file descriptor at E:/www/cgi-bin/pg93ex3.11SeriesOfNumbers.pl line 14. I've narrowed the problem down to the "if" block (the regex), I'd like to accept numbers and spaces only. Here's the code: #!E:/www/perl/bin/perl.exe use strict; use warnings; use CGI qw( :standard ); use CGI::Carp qw( fatalsToBrowser ); print header(); my $userIn = param( "textfield" ); if ( $userIn =~ /^(\d+|\s*)$/ ) { $userIn = $1; } else { die "Please, enter numbers separated by spaces only!: $!"; } my @numbers = split( / /, $userIn ); my $total = scalar( @numbers ); my @sorted = sort( @numbers ); my $smallestNum = @sorted[0]; my $largestNum = @sorted[-1]; my $sum = 0; foreach ( @numbers ) { $sum += $_; } my $average = ( $sum / $total ); print<<HTML; <html> <head> <title>Series of Numbers</title> <style type="text/css"> <!-- .style1 { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; } body,td,th { font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 10pt; } --> </style> </head> This page accepts a series of numbers, separated by spaces, and gives the values listed bellow. <form action="" method="post" name="form1" class="style1" id="form1"> <table width="448" border="0"> <tr> <td width="270"><div align="right">Enter your numbers here: </div></td> <td width="165"><input type="text" name="textfield" /></td> </tr> <tr> <td colspan="2"> <div align="center"> <a href="http://mail.yahoo.com/config/login?/pg93ex3.11SeriesOfNumbers.html"> Click here to go back! </a> </div></td> </tr> <tr> <td><div align="right">The total number of numbers entered is: </div></td> <td> $total </td> </tr> <tr> <td><div align="right">The smallest number is: </div></td> <td> @sorted[0] </td> </tr> <tr> <td><div align="right">The largest number is: </div></td> <td> @sorted[-1] </td> </tr> <tr> <td><div align="right">The sum of all the numbers is: </div></td> <td> $sum </td> </tr> <tr> <td><div align="right">The average of all the numbers is:</div></td> <td> $average </td> </tr> </table> </form> </html> HTML Ron Smith [EMAIL PROTECTED]