Created
October 2, 2020 16:51
-
-
Save tobyink/48d5e2cefe97ab2bbcfa929a914796df to your computer and use it in GitHub Desktop.
Sub::Operable Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use strict; | |
use warnings; | |
use feature 'say'; | |
use List::Util 'shuffle'; | |
use Sub::Operable 'subop'; | |
*greetings = subop { | |
my @greetings = shuffle( | |
'Greetings', | |
'Hello', | |
'Good Morning', | |
); | |
return $greetings[0]; | |
}; | |
say greetings(); | |
say greetings(); | |
say "--"; | |
*place = subop { | |
my @places = shuffle( | |
'Earth', | |
'World', | |
'Vietnam', | |
); | |
return $places[0]; | |
}; | |
say place(); | |
say place(); | |
say "--"; | |
# | |
# We're concatentating two coderefs and a string?!??! | |
# | |
*greet_place = \&greetings . " " . \&place; | |
say greet_place(); | |
say greet_place(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment