Skip to content

Instantly share code, notes, and snippets.

@sirhc
Created July 25, 2014 21:34
Show Gist options
  • Save sirhc/029226ab70d0c33ac98e to your computer and use it in GitHub Desktop.
Save sirhc/029226ab70d0c33ac98e to your computer and use it in GitHub Desktop.
Add a whilst keyword to Perl
#!/usr/bin/perl
#
# Inspired by https://github.com/mattt/BritishInvasion
#
# This is still a terrible idea. Just dreadful.
use 5.016;
use warnings;
BEGIN {
package BritishInvasion;
use Keyword::Simple;
sub import {
Keyword::Simple::define( 'whilst', sub {
my $ref = shift;
substr( $$ref, 0, 0 ) = 'while';
} );
}
sub unimport {
Keyword::Simple::undefine('whilst');
}
}
BEGIN {
BritishInvasion->import;
}
my $i = 0;
whilst ( $i < 10 ) {
say $i++;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment