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 $anonsub = sub { return join ',', @_; }; | |
| $anonsub->(1,2,3,4); |
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 make_closure { | |
| my @inputs = @_; | |
| return sub { join ',', @inputs, @_; }; | |
| } | |
| my $closure = make_closure(1,2,3,4); | |
| say $closure->('X'); | |
| undef $closure; |
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
| # First, let's prove that DestroyDetector announces when undef'ed. | |
| my $foo1 = DestroyDetector->new('foo1'); | |
| $foo1->announce("about to undef foo1"); | |
| undef($foo1); | |
| # Now, let's define a function which returns a closure... | |
| sub closure_one { | |
| my ($value) = @_; | |
| my $detector = DestroyDetector->new($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
| #!/usr/bin/env perl | |
| use 5.010; # Perl 5.10 minimum! | |
| use strict;use warnings; | |
| # This is just to demonstrate a simple closure | |
| sub make_closure { | |
| my @inputs = @_; | |
| return sub { join ',', @inputs, @_; }; | |
| } |
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
| use strict;use warnings; | |
| require 5.010; | |
| package UseOrRequire; | |
| sub INIT { | |
| say 'INIT CALLED!'; | |
| } | |
| sub BEGIN { |
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
| package Animal; | |
| use Moose; | |
| has 'name' => (is=>'rw',isa=>'Str'); | |
| sub say_my_name { | |
| my ($self) = @_; | |
| say $self->name; | |
| } |
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
| #!/bin/bash -x | |
| gcc cunit_demo.c -lc -lcunit -L"/usr/local/lib" -o cunit_demo |
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
| # /* | |
| use strict; | |
| use warnings; | |
| use 5.010; | |
| package BinSearch; | |
| use Inline C => 'DATA' => (LIBS=>'m'); | |
| Inline->init; |
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 binsearch_with_sort { | |
| my ($needle, $haystack) = @_; | |
| my $sorted = [sort @{$haystack}]; | |
| my $left = 0; | |
| my $right = scalar(@{$sorted}); | |
| my $look = undef; | |
| if ($right <= 1) { |
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
| #!/usr/bin/env perl | |
| use strict; use warnings; | |
| if (scalar(@ARGV) != 1) { | |
| die "Usage: $0 INTEGER"; | |
| } | |
| my $in = $ARGV[0]; | |
| if ($in !~ m/^-?[0-9]+$/) { | |
| die "Usage: $0 INTEGER (and it really must be an integer)"; |