Groups | Search | Server Info | Login | Register
Groups > comp.lang.awk > #10024
| From | Mike Sanders <porkchop@invalid.foo> |
|---|---|
| Newsgroups | comp.lang.awk |
| Subject | Re: nested ternary discovery |
| Date | 2025-10-11 11:55 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <10cdgkc$nu0u$2@dont-email.me> (permalink) |
| References | <10c866d$2lhr4$1@dont-email.me> <68e8bf90$0$671$14726298@news.sunsite.dk> |
On 10 Oct 2025 08:10:56 GMT, Mack The Knife wrote:
> This is where associative arrays shine:
>
> BEGIN {
> annimal["bark"] = "dog"
> annimal["meow"] = "cat"
> annimal["moo"] = "cow"
> # etc. ...
> }
> { print animal[$1] }
>
> Much simpler, and each additional sound/animal pair requires
> only one additional line of code.
I dont know, I'm torn here...
Associative arrays, as I'm sure you'd agree, are a quintessential
awk feature & really do make coding chores so much easier. And yet
for a short logic block, I think ternary has it beat:
scale = (unit == "T") ? 1e12 :
(unit == "B") ? 1e9 :
(unit == "M") ? 1e6 :
(unit == "K") ? 1e3 : 1
Nice, compact, even symmetrical looking. Doubly so one liners.
At any rate, your point is true & I appreciate your remarks Mack.
Me? Just posting what I learn on my journey in the hopes that
others will do likewise =)
Back to comp.lang.awk | Previous | Next — Previous in thread | Next in thread | Find similar
nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-09 11:27 +0000
Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-09 17:09 +0200
Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-10 19:38 +0000
Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-11 11:46 +0000
Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-11 16:58 +0000
Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-12 03:47 +0000
Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-12 01:54 +0200
Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-12 03:49 +0000
Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-09 16:59 +0000
Re: nested ternary discovery mack@the-knife.org (Mack The Knife) - 2025-10-10 08:10 +0000
Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-10 13:06 +0200
Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-10 17:04 +0000
Re: nested ternary discovery mack@the-knife.org (Mack The Knife) - 2025-10-11 17:44 +0000
Re: nested ternary discovery Kaz Kylheku <643-408-1753@kylheku.com> - 2025-10-11 18:46 +0000
Re: nested ternary discovery mack@the-knife.org (Mack The Knife) - 2025-10-13 08:07 +0000
Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-10 19:41 +0000
Re: nested ternary discovery Mike Sanders <porkchop@invalid.foo> - 2025-10-11 11:55 +0000
Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-12 01:45 +0200
Re: nested ternary discovery dave_thompson_2@comcast.net - 2025-10-12 20:58 -0400
Re: nested ternary discovery Janis Papanagnou <janis_papanagnou+ng@hotmail.com> - 2025-10-13 04:30 +0200
csiph-web