Live data from Hacker News

Ask HN: What can you do in one language that can't be done as well in others?

news.ycombinator.com

1–10 of 30 posts

Re: Ask HN: What can you do in one language that can't be done as well in others?

#3
post #2

Bash shell script: using pipes → « cat MonFichier | while read LaLigne ; do echo $LaLigne ; done »

It's also one of the coolest features in Elixir IMO.

http://elixir-lang.org/getting-started/enumerables-and-strea...

Re: Ask HN: What can you do in one language that can't be done as well in others?

#5
I know PHP isn't very popular here, but it's awesome for string manipulation, parsing files.

One-line that reads the file, splits multiple lines into an array:

    
Want to sort them alphabetically? Add

    sort($l);
Trim them?

    $trimmed = array_map(trim, $l);
Remove duplicates?

    $unique = array_unique($trimmed);

Re: Ask HN: What can you do in one language that can't be done as well in others?

#7
post #2

Bash shell script: using pipes → « cat MonFichier | while read LaLigne ; do echo $LaLigne ; done »

Pipes are pretty prevalent in PowerShell too.

Though not as useful as in Bourne shell, as you can't save intermediate results to review or reprocess them.

Re: Ask HN: What can you do in one language that can't be done as well in others?

#8

I know PHP isn't very popular here, but it's awesome for string manipulation, parsing files. One-line that reads the file, splits multiple lines into an array: Want to sort them alphabetically? Add sort($l); Trim them? $trimmed = array_map(trim, $l); Remove duplicates? $unique = array_unique($trimmed);

Most languages have these type of functions, once you've read the file into an array its just array/list manipulation. I haven't compile checked this but here's the same as a C# one liner:

List lines = File.ReadAllLines("/file.txt").Distinct().ToList().Select(l => l.Trim()).Sort();

Re: Ask HN: What can you do in one language that can't be done as well in others?

#9

I know PHP isn't very popular here, but it's awesome for string manipulation, parsing files. One-line that reads the file, splits multiple lines into an array: Want to sort them alphabetically? Add sort($l); Trim them? $trimmed = array_map(trim, $l); Remove duplicates? $unique = array_unique($trimmed);

Even simpler, and handles the different new line characters:

  $l = file('in.txt', FILE_IGNORE_NEW_LINES);
Post reply on HN