4 ms·
Didn't know Ruby (and Perl?) had BEGIN and END... pretty cool. However I would just write the final example as: curl -s http://www.gutenberg.org/files/1080/10
by chubot 16y ago
Didn't know Ruby (and Perl?) had BEGIN and END... pretty cool. However I would just write the final example as:
curl -s http://www.gutenberg.org/files/1080/1080.txt http://www.gutenberg.org/files/1080/1080.txt | tr ' \t' '\n\n' | sort | uniq -c | sort -n
and avoid any kind of procedural programming.
- rtomayko 16y agoMe too :) Actually, check out the talk mentioned at the beginning of the essay. Pretty sure I build that exact pipeline at some point near the middle.
- draegtun 16y agoDidn't know Ruby (and Perl?) had BEGIN and END... Along with BEGIN & END there is also UNITCHECK, CHECK & INIT in Perl: http://perldoc.perl.org/perlmod.html#BEGIN%2c-UNITCHECK%2c-CHECK%2c-INIT-and-END http://perldoc.perl.org/perlmod.html#BEGIN%2c-UNITCHECK%2c-C... These named blocks are used under the hood in Perl all the time. For eg. foo(); # => bar sub foo { say "bar" } The above works because the last line is interpreted as: BEGIN { *foo = sub { say "bar" } } And so is compiled before the foo() line is reached/run. PS. Perl6 goes even further and calls them Phasers: http://feather.perl6.nl/syn/S04.html#Phasers http://feather.perl6.nl/syn/S04.html#Phasers