Skip to content

Instantly share code, notes, and snippets.

@rjbs
Created February 1, 2014 19:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rjbs/8757352 to your computer and use it in GitHub Desktop.
Save rjbs/8757352 to your computer and use it in GitHub Desktop.
BEGIN { unshift @INC, 'lib'; }
use 5.19.0;
use feature 'signatures';
use warnings;
no warnings 'experimental::signatures';
sub add ($x, $y = 0) { return $x + $y; }
use JSON::PP;
sub obj (%data) { say JSON::PP->new->encode(\%data) }
say add(1,2) // -1;
say add(6) // -1;
say obj(%INC);
use Data::Dumper;
sub foo ($, $z = undef, @) { say Dumper(\@_) }
sub bar ($=, $z = undef, @) { say Dumper(\@_) }
foo(1,2);
bar(1,2);
bar();
sub add2 ($x, $y = return $x) { return $x + $y; }
say add2(123);
say add2(123,321);
sub xyz( $p1, $p2 = 3, $p3 = 4 ) { say "p1 = $p1, p2 = $p2, p3 = $p3" }
say xyz(10, ,70);
package X {
sub new ($class, $arg) { bless $arg, $class }
sub dump ($self) { say Data::Dumper::Dumper($self) }
}
my $x = X->new({});
$x->dump;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment