5 ms·
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 spac
by cbsmith 5y ago
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.
- 613style 5y agoI 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.
- cbsmith 5y agoIs 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.
- cbsmith 5y agoWeird, not sure why it did % instead of $ there.
- RasmusLarsen 5y agoIn the context of trying to teach people basics, yes, I would argue that is quite awful.
- samatman 5y agoIt'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.
- tasogare 5y agoSame 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.
- cbsmith 5y agoYou don't even need a full programming language... just something that does pattern matching that lets you grab "last word from a line".