Re:C++ has become a scripting language
by Freaky on Wednesday October 16, 2013 @08:37AM
(#6559278)
You're fired.
[ Parent
| on HN ]
Re:C++ has become a scripting language
by Aaronneyer on Wednesday October 16, 2013 @08:53AM
(#6559349)
Here's the shortest I've gotten after looking at some of the comments:
IO.write$*.pop,ARGF.lines.sort.join
And yes, it does work even without the space between `write` and `$*`.Also after testing, I realized the ('\n') is not required for join. When you call 'lines', it still has the '\n' character in the string, and when you join, it defaults to join without a delimiter, so it's putting them back together with the newline still there.
Re:C++ has become a scripting language
by danmaz74 on Wednesday October 16, 2013 @08:48AM
(#6559333)
Wow, this is really sweet and esoteric (didn't know about ARGF) - but, reading the docs for ARGF, wouldn't it also try to ready from ARGV[1]?
Maybe this would fix it:
IO.write(ARGV.pop, ARGF.lines.sort.join('\n'))Yes, good catch. join('\n') is wrong though - IO#lines preserves newlines, the default join is the empty string, and you meant "\n" :)
Re:C++ has become a scripting language
by danmaz74 on Wednesday October 16, 2013 @11:14AM
(#6560089)
:)
Re:C++ has become a scripting language
by Aaronneyer on Wednesday October 16, 2013 @08:48AM
(#6559332)
I believe you still need to join on newline, the default is space. However you can save a couple characters by using `$*` instead of ARGV.
Also, trim out the space between the arguments and kill the parenthesis for the optimal golfing.