News for hackers. Stuff that matters.
Re:AWK-ward Ruby by draegtun on Tuesday April 26, 2011 @03:22PM (#2486746)
Didn'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-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

There are no comments on this comment yet.