Re: Error in the "if" block

2006-02-20 Thread Chas Owens
On 2/20/06, John W. Krahn <[EMAIL PROTECTED]> wrote: snip > my ( $smallestNum, $largestNum ) = ( sort { $a <=> $b } @numbers )[ 0, -1 ]; > > Although as I said, the for loop is more efficient. snip Ah this old chestnut. Depending on the size of the array sort is faster (after 200 or so items for

Re: Error in the "if" block

2006-02-20 Thread Ron Smith
> > Sorry, my mistake, that should really be: > > my ( $smallestNum, $largestNum ) = ( sort { $a <=> > $b } @numbers )[ 0, -1 ]; > > Although as I said, the for loop is more efficient. > It just amazes me as to how *flexable* Perl is. Ron Smith [EMAIL PROTECTED] -- To unsubscribe, e-mail:

Re: Error in the "if" block

2006-02-20 Thread Ron Smith
> > Sorry, my mistake, that should really be: > > my ( $smallestNum, $largestNum ) = ( sort { $a <=> > $b } @numbers )[ 0, -1 ]; > > Although as I said, the for loop is more efficient. > I just amazes me as to how *flexable* Perl is. Ron Smith [EMAIL PROTECTED] -- To unsubscribe, e-mail: [

Re: Error in the "if" block

2006-02-20 Thread John W. Krahn
Ron Smith wrote: > --- "John W. Krahn" <[EMAIL PROTECTED]> wrote: >> >>But since you are sorting numbers, you probably want >>to do a numeric sort to >>get the correct numbers: >> >>my ( $smallestNum, $largestNum ) = sort { $a <=> $b >>} @numbers; >> > I'm using: my @sorted = sort { $a <=> $b } @nu

Re: Error in the "if" block

2006-02-19 Thread Ron Smith
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > Ron Smith wrote: > Hans Meier (John Doe) wrote: > >> > >>The if-else could be shortened to (untested, so > >>please check): > >> > >>die "Bla" unless > >>($userIn)=$userIn=~/^\s*((?:\d+\s*?)+)\s*$/; > > > > Right; a lot shorter. Why, the parenthes

Re: Error in the "if" block

2006-02-19 Thread Ron Smith
--- "John W. Krahn" <[EMAIL PROTECTED]> wrote: > Your problem is that you are using the $! variable: > > But you are using it for a pattern match failure > which is neither a system nor > a library call. > > > my @numbers = split( / /, $userIn ); > > I would write that as: > > my @numbers = $

Re: Error in the "if" block

2006-02-19 Thread Hans Meier (John Doe)
Ron Smith am Sonntag, 19. Februar 2006 21.27: > I changed this too. Thanks, Hans! > > > [irrelevant parts snipped away] The "irrelevant" was not quite true... As always, John W. Krahn looked closer into the code, finds simpler solutions and does not miss to point to the appropriate documentation

Re: Error in the "if" block

2006-02-19 Thread John W. Krahn
Ron Smith wrote: Hans Meier (John Doe) wrote: >> >>The if-else could be shortened to (untested, so >>please check): >> >>die "Bla" unless >>($userIn)=$userIn=~/^\s*((?:\d+\s*?)+)\s*$/; > > Right; a lot shorter. Why, the parentheses around > $userIn? Context. Without the parentheses you have scala

Re: Error in the "if" block

2006-02-19 Thread John W. Krahn
Ron Smith wrote: > Hi all, Hello, > 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

Re: Error in the "if" block

2006-02-19 Thread John W. Krahn
Ron Smith wrote: > Hi all, Hello, > 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

Re: Error in the "if" block

2006-02-19 Thread Ron Smith
> > No information about the input that causes the > error; are there also inputs > not causing an error? Yes, the input expected would be: " 32 11 25" or "32 11 25 " or " 32 11 25 " ...etc. > > What you want is something like > > /^\s*((?:\d+\s*?)+)\s*$/ > > The inner (?:) does not capture

Re: Error in the "if" block

2006-02-19 Thread Hans Meier (John Doe)
Ron Smith am Sonntag, 19. Februar 2006 18.47: > Hi all, Hi Ron > This page accepts a series of numbers, separated by spaces, and gives the > values listed bellow. > I'm getting the following error, No information about the input that causes the error; are there also inputs not causing an e