]> Dogcows Code - chaz/talk-level-up-your-perl/commitdiff
add more examples of new perl5 features
authorCharles McGarvey <cmcgarvey@bluehost.com>
Fri, 8 Jun 2018 06:12:51 +0000 (00:12 -0600)
committerCharles McGarvey <cmcgarvey@bluehost.com>
Fri, 8 Jun 2018 06:12:51 +0000 (00:12 -0600)
css/slides.css
slides.html

index 6ba8dc1221744af3f51636211bab523a6c7340ec..076d14a4e5c13d7dd18deb1b8c1e514b6ed06e88 100644 (file)
 .ex-newfeatures .perl {
     font-size: 22px;
 }
+.ex-newfeatures2 .perl {
+    font-size: 32px;
+}
 .ex-moo .perl {
     font-size: 29px;
 }
index 004c261e8058658e43c9b8fe56e6a139b253f711..4ebcc71e3d1b49cff66dc4e3aa0881512d466c47 100644 (file)
@@ -1412,57 +1412,66 @@ sub launch_missile ( $silo_id = get_default_silo_id() ) {
 ---
 class: ex-newfeatures
 
-## Try some newer perl5 features.
+### Postfix dereferencing
 
 ```perl
-*use v5.24;
-*use feature qw(signatures);    # available in v5.20
-*no warnings qw(experimental::signatures);
-
-my $missile_inventory = {
-    ID  => 20,
-    WY  => 25,
-    CA  => 195,
-};
+use v5.24;
 
-*sub get_default_silo_id () {
-    return $_ if 0 < $missile_inventory->{$_} for (sort keys $missile_inventory->%*);
-    die "No more missiles. :-(\n";
+my $person = {
+    name => 'Bob',
+    associates => [
+        {
+            name => 'Karen',
+        },
+        {
+            name => 'Doug',
+        },
+    ],
 }
 
-*sub launch_missile ( $silo_id = get_default_silo_id() ) {
-    die "Silo is empty.\n" if $missile_inventory->{$silo_id} <= 0;
-    $missile_inventory->{$silo_id} -= 1;
-    say "Missile launched from silo $silo_id.";
-}
+my @others = $person->{associates}->@*;
+my %associate_attributes = $person->{associates}->@[0]->%*;
 ```
 
+### `@{...}` can be `->@*` at the end
+### `%{...}` can be `->%*` at the end
+
 ---
-class: ex-newfeatures
+class: ex-newfeatures2
 
-## Try some newer perl5 features.
+### Subroutine signatures
 
 ```perl
-use v5.24;
-use feature qw(signatures);    # available in v5.20
+use v5.20;
+use feature qw(signatures);
 no warnings qw(experimental::signatures);
 
-my $missile_inventory = {
-    ID  => 20,
-    WY  => 25,
-    CA  => 195,
-};
+sub only_one_arg($foo) {
+}
 
-sub get_default_silo_id () {
-*   return $_ if 0 < $missile_inventory->{$_} for (sort keys $missile_inventory->%*);
-    die "No more missiles. :-(\n";
+sub other_args_allowed_and_ignored($foo, @) {
 }
 
-sub launch_missile ( $silo_id = get_default_silo_id() ) {
-    die "Silo is empty.\n" if $missile_inventory->{$silo_id} <= 0;
-    $missile_inventory->{$silo_id} -= 1;
-    say "Missile launched from silo $silo_id.";
+sub positional_and_named($args, %other) {
 }
+
+# etc.
+```
+
+---
+class: ex-newfeatures2
+
+### Strip leading space in heredocs
+
+```perl
+use v5.26;
+
+do {
+    print <<~'HERE';
+    Hi. The text here is indented in the source code,
+    but not in the console!
+    HERE;
+};
 ```
 
 ---
This page took 0.023222 seconds and 4 git commands to generate.