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
>
> 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:
>
> 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: [
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
--- "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
--- "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 = $
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
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
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
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
>
> 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
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
12 matches
Mail list logo