Re: What's the best way to find min and max values in an array with undefined members without getting error messages?
[email protected] (Levi Nystad-Johansen via beginners) Tue, 19 May 2026 09:06:17 +0000
| Newsgroups | perl.beginners |
|---|---|
| Message-ID | <hDNhnbtciPS72hB_fUWqnevxkmzvePPHtD0l7g5xmBEmU6o7TJfBRh1SFFrrAUzoMe0RaecZT1yw7MQAbp8rFCYPb5aJXd2pNTushBC35ZQ=@protonmail.com> |
You can just add "grep defined," before the list/array:=20
printf("%d\n", min grep defined, (1, undef));
-Levi
On Tuesday, May 19th, 2026 at 8:50 AM, hw via beginners <[email protected]=
> wrote:
>=20
> # perl -e '
> use warnings;
> use List::Util qw(min);
> printf("%d\n", min(1, undef));
> '
> Use of uninitialized value in subroutine entry at -e line 1.
> Use of uninitialized value in printf at -e line 1.
> 0
>=20
>=20
> Are there alternative min and max functions that skip undef array
> members, or I'm better off to write my own?
>=20
> --
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> http://learn.perl.org/
>=20
>=20
>