Re:The Unix Game
by cbsmith on Friday May 28, 2021 @05:22PM
(#27320679)
Maybe it's just me, but I was already turned off by the use of "cut" in the first question in a way that assumes all the names in the file have exactly one space and exactly two names.
[ Parent
| on HN ]
It's a game.
I'd be more bummed if a game gave me five lines of sample data which fit the constraint of "exactly one space and exactly two names", and then the rest of the data violated that constraint.
Or if some of the last names didn't start with a capital letter, like d'Azzo, for that matter.
I think there's two parts to this: first, if you know your input meets certain constraints, then there's no benefit to over-complicating the solution. Second, this is a teaching tool. It makes sense to start simply and save the harder version for later.
Is it really so awful to do "grep -o '\b\w+%'"? It still won't handle extra space padding at the end of the line, but it's still a lot less ugly than assuming the word after the first space is a last name.
Re:The Unix Game
by RasmusLarsen on Saturday May 29, 2021 @03:07AM
(#27323567)
In the context of trying to teach people basics, yes, I would argue that is quite awful.
Weird, not sure why it did % instead of $ there.
Same thought here. Processing text with cut and pipes is cute and works when data are regular except in real life there is often lines here and there breaking assumptions. Using a programming language offer way more possibilities to deal with pathological cases.