This file contains hidden or 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
| sub { say 'Hello World!' }; |
This file contains hidden or 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
| my $hello = sub { say 'Hello World!' }; |
This file contains hidden or 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
| my $hello = sub { say 'Hello World!' }; | |
| $hello->(); |
This file contains hidden or 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
| my $say = sub {say $_[0]}; | |
| $say->('Hello World!'); |
This file contains hidden or 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
| my $outer = sub | |
| { | |
| my ($subject) = @_; | |
| my $inner = sub | |
| { | |
| my ($salutation, $subject) = @_; | |
| say "$salutation $subject!"; | |
| } |
This file contains hidden or 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
| my %evocations = ( | |
| say => sub { say shift; }, | |
| shout => sub { say uc shift; } | |
| ); | |
| $evocations{say}->("Hello"); | |
| $evocations{shout}->("Hello"); |
This file contains hidden or 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
| my $get_input = sub { my $ret = <>; chomp $ret; return $ret;}; | |
| my $request = sub { print "Please provide your age: "; $get_input->()}; | |
| my @prompts = ( | |
| $request, | |
| $request, | |
| sub { print "PLEASE PROVIDE YOUR AGE: "; $get_input->() }, | |
| sub { say "Fine, whatever, forget it."; return; } | |
| ); | |
| my $age; |
This file contains hidden or 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
| { | |
| my $value = 11; | |
| sub get_value { $value }; | |
| } | |
| say get_value->(); # Succeeds in printing "11\n" |
This file contains hidden or 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
| { | |
| my $value = 11; | |
| } | |
| say $value; |
This file contains hidden or 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
| my $fun | |
| { | |
| my $value = 42; | |
| $fun = sub {$value}; | |
| } | |
| say $fun->(); # prints "42\n" |
OlderNewer