-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
77 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
class Cafe { | ||
has $.name; | ||
has @!orders; | ||
|
||
method order($what) { | ||
@!orders.push($what); | ||
} | ||
|
||
method list-orders { | ||
@!orders.sort.join(', ').say; | ||
} | ||
} | ||
|
||
my $cafe = Cafe.new( | ||
name => "Paris" | ||
); | ||
|
||
$cafe.order('meet'); | ||
$cafe.order('fish'); | ||
$cafe.list-orders; # fish, meet |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
class A { | ||
has $.x = 42; | ||
method m { | ||
say "A.m"; | ||
} | ||
} | ||
my A $c = A.new(x => 14); | ||
say $c.x; # 14, not 42 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
use DBIish; | ||
|
||
my $dbh = DBIish.connect( | ||
'mysql', | ||
:host<example.com>, | ||
:port(3306), | ||
:database<test>, | ||
:user<test>, | ||
:password<test_password> | ||
); | ||
|
||
my $sth = $dbh.prepare("insert into calendar values (?, ?)"); | ||
$sth.execute('2017-01-02', 'Wake up'); | ||
|
||
$sth.finish; | ||
$dbh.dispose; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
"Perl’s Birthday: 18 December 1987" ~~ | ||
/(\d+)\s(\D+)\s(\d+)/; | ||
/ (\d+) \s (\D+) \s (\d+) /; | ||
say $/.Str; | ||
say $/[$_] for 0..2; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
my %month-abbrs = | ||
:jan('January'), | ||
:feb('February'), | ||
:mar('March'); | ||
say %month-abbrs<mar>; # prints March |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
my @a = 1, 2, 3, 5, 7, 11; | ||
|
||
say @a; # [1 2 3 5 7 11] | ||
say "This is @a: @a[]"; # This is @a: 1 2 3 5 7 11 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
say 20 min 10; | ||
say 'three' max 'two'; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
my Int $x; | ||
$x = "123".Int; # Now this is OK | ||
say $x.Int; | ||
say $x; # 123 |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# $p1 is Kept | ||
my $p1 = start { | ||
my $inf = 1 / 0; | ||
} | ||
|
||
# $p2 is Broken | ||
my $p2 = start { | ||
my $inf = 1 / 0; | ||
say $inf; | ||
} | ||
|
||
|
||
sleep 1; # Wait until the code blocks are done | ||
|
||
say $p1.status; # Kept | ||
say $p2.status; # Broken |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
try { | ||
say 42/0; | ||
} | ||
say $!; | ||
say $! if $!; |