Skip to content

Instantly share code, notes, and snippets.

@tobyink
Created October 2, 2020 16:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tobyink/48d5e2cefe97ab2bbcfa929a914796df to your computer and use it in GitHub Desktop.
Save tobyink/48d5e2cefe97ab2bbcfa929a914796df to your computer and use it in GitHub Desktop.
Sub::Operable Example
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