Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

It's definition under my definition of 'hacking.' Consider that the GNU tools already implement non-portable extensions; this would be yet another one, were it added. Also, portability is not an essential requirement for "hacking." I do small programming exercises sometimes in order to understand a facet of how things work. Consider this as an exercise in how to use locale-dependent specifiers.

As I pointed out elsewhere, your sed code doesn't work because it changes too many numbers - including filenames and dates - in the output. Also, if the exercise is to understand localization then your sed code isn't appropriate because it hard-codes "," when some locales use a "." as the thousands separator.

And for completeness, your alias can't then mix and match other flags, like "ls -lRt". It's a single command with strange side-effects if you use it incorrectly:

    % lll -art
    sed: illegal option -- r
    usage: sed script [-Ealn] [-i extension] [file ...]
           sed [-Ealn] [-i extension] [-e script] ... [-f script_file] ... [file ...]


Hmmm - the sed code was written to give a working 1 line example with the answer- just an example, or else some people might consider that it could be high-end wizardy worthy of recompilation.

Instead of complaining about an obvious flaw in the example, maybe you could be more constructive and fix it.

Hints:

- if you want to pass other flags, make it a function and use $@

- if you want to respect the filenames and dates, either fix the regex or write it in perl.

Shouldn't take you long - back from 1999 in perl FAQ:

http://www.perlmonks.org/?node_id=653

But now it's qualifies as hacking. I guess that's due to inflation.

This is so not hacker news.

Ask a perl golfer to make you a one-liner you can copy-paste in your profile if you absolutely need some working code.


You did not give a `working 1 line example with the answer.' It doesn't do the right thing, and I pointed out two failure cases.

My constructive criticism is that your approach is wrong, should not be done, and cannot be easily fixed. One should never attempt to process the general output of ls. It's doable - I lived through the years of processing the "list"/"ls" output from random ftp servers - but it's nasty. Sure, you can add '$@' but then you have to worry about, say, "-i", which shows the inode number as a new leading column or "-n" which shows user/group ids instead of names. How does your alias/perl script figure out which column is the one which needs the commas?

You'll either end up with a very fragile system (producing the erroneous output as your 1-liner does) or you'll end up trying to understand most of the ls command-line arguments and/or heuristics to guess based on the output. The well-known "BUGS" section of the Unix man page says "To maintain backward compatibility, the relationships between the many options are quite complex." You're in for a long slog if you go this route.

Yes, if you want a one-off solution for a specific set of outputs then your approach would work. That would be also be boring and trivial. The linked-to article, on the other hand, was interesting.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: