Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Perl v5.26 Features (AmsterdamX.pm)

372 views

Published on

A survey of new features of Perl v5.26, at AmsterdamX.pm.

Published in: Technology
  • Be the first to comment

  • Be the first to like this

Perl v5.26 Features (AmsterdamX.pm)

  1. 1. Perl v5.26 New Features AmsterdamX.pm, 8 Jun 2017 Tunisian Camels (2010), from Ray on Flickr
  2. 2. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures scalar %hash
  3. 3. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures The key count • A hash in scalar context returned “hash statistics” my %h = (a=>1, b=>2); say scalar %h; # ‘2/8’ • Everyone expected it to be the number of keys • Now that’s what they get. my %h = (a=>1, b=>2); say scalar %h; # 2
  4. 4. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures POSIX::tmpnam
  5. 5. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures use File::Temp qw/ tempfile tempdir /; $fh = tempfile(); ($fh, $filename) = tempfile(); ($fh, $filename) = tempfile( $template, DIR => $dir); ($fh, $filename) = tempfile( $template, SUFFIX => '.dat'); ($fh, $filename) = tempfile( $template, TMPDIR => 1 );
  6. 6. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures {
  7. 7. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures Regexes are messier • N{NAME}, x{ABCD}, p{PROPERTY}, P{PROPERTY}, b{…}, B{…}, a{MIN,MAX}, and so on • New things are probably on the way • So, every { is now special and not literal • Some old tools might break
  8. 8. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures /xx
  9. 9. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures More Meaninglessness • /x makes most whitespace in a regex insignificant • And, you can add comments inside regex • Except in a character class [ a b c ] • Or [ a #comment b c ] • Previously, Perl ignored additional /x • Maybe you added /xxx to honor Amsterdam. • Now you can’t. • /xx now applies the rules inside a char class
  10. 10. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures Apple Part Number my $string = ' Z007LL/A'; my $pattern = qr/ A # M = First sale, F = Refurbished, P = Personalized [ M F P ] # probably not all these letters here [ A-Z ] d+ (?: # country codes LL | [ FBEJTXYC ] ) / [ A B C ] # revision z /xx; say $string =~ $pattern ? 'Matched' : 'Missed';
  11. 11. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures Hopes for /xxx (?:L [ A # Colombia, Ecuador, El Salvador, … Peru E # Argentina L # US Z # Chile, Paraguay, Uruguay ] | [ F # France B # Ireland, UK E # Mexico J # Japan T # Italy X # Australia, New Zealand Y # Spain C # Canada ] )
  12. 12. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures Indented Heredocs
  13. 13. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures my $string = <<~“HERE"; This is the first line This is the second line HERE This is the first line This is the second line
  14. 14. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures my $string = <<~“HERE"; This is the first line This is the second line HERE This is the first line This is the second line
  15. 15. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures No . in @INC
  16. 16. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures More Securitiness • What’s that . anyway? • This doesn’t mean that you are safe • CPAN tested, but not DarkPAN tested • do warns when it fails to load a file from . • You can disable this, but I won’t tell you how
  17. 17. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures @{^CAPTURE}
  18. 18. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures List of Captures • %{^CAPTURE} is %+ (named captures) • %{^CAPTURE_ALL} is %- (all named captures) • @{^CAPTURE} is the cool one. • ${^CAPTURE}[INDEX] is the numbered capture minus 1
  19. 19. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures sub match_it_1 ( $rx, $string ) { $string =~ $rx; say "$1•$2•$3"; # Hoping there's three } sub match_it_2 ( $rx, $string ) { $string =~ $rx; say join '•', map { substr $string, $-[$_], $+[$_]-$-[$_] } 1 .. $#-; } sub match_it_3 ( $rx, $string ) { $string =~ $rx; local $" = '•'; say "@{^CAPTURE}"; }
  20. 20. ThePerlReview•www.theperlreview.com Perlv5.26NewFeatures Questions

×