3 ms·
>What is so hard about it? quick: without looking anything up, write something in bash that takes a string of comma-separated values and turns it into an array
by _dain_ 5y ago
>What is so hard about it?
quick: without looking anything up, write something in bash that takes a string of comma-separated values and turns it into an array of those values.
then check to see if your answer is on this very long list of wrong implementations:
https://stackoverflow.com/a/45201229/6107981 https://stackoverflow.com/a/45201229/6107981
- asdff 5y agoEasy, I just avoid these sort of mind game situations when programming, and I come up with a simple 'wrong' approach that will probably work fine for my purposes anyhow. I don't care if my implementation breaks if I have a newline in my data or whatever, because I already know based on what I am working on that I won't have to worry about a newline in my data or any other weird quirks they bring up in stack overflow comment sections that I have yet to come across in my years of writing code that gets the job done. I don't care if my solution is fractions of a second slower, it's probably already going to be mindbendingly fast compared to the code running on hardware from 40 years ago when people had to be a lot more mindful about selecting the most performant solutions when writing in bash or anything else.
- _dain_ 5y agoOkay, but how do you know that those weird quirks won't be present in your data? Or what those weird quirks even are? The details of the stuff in that Stackoverflow comment have already fallen out of my head; I couldn't tell you about them now. With Bash there are so many traps and footguns and (subjective) unknown unknowns, it would keep me up at night worrying about it. There's always another maddening fact to discover. I would just use Python, where strings are sane and lists are sane: my_string.split(", "), boom, done, no jumpscares.