SlideShare uma empresa Scribd logo
1 de 184
Baixar para ler offline
Perl 5.10
for people who are not insane
Perl 5.10
for people who are not totally insane
5.10 isn’t like 5.8.x




                    perl5100delta
5.10 isn’t like 5.8.x


- features only get added in new 5.x releases



                                          perl5100delta
5.10 isn’t like 5.8.x


- features only get added in new 5.x releases
- it’s been 5 years since the last release (5.8)


                                            perl5100delta
5.10 is Way Cool




                   perl51000delta
5.10 is Way Cool

- no significant new features in Perl since 2002




                                        perl51000delta
5.10 is Way Cool

- no significant new features in Perl since 2002
- remember how bad you wanted to see Star
  Wars: Episode 1?




                                        perl51000delta
5.10 is Way Cool

- no significant new features in Perl since 2002
- remember how bad you wanted to see Star
  Wars: Episode 1?
- that’s how excited you should be for 5.10


                                        perl51000delta
5.10 is Way Cool

- no significant new features in Perl since 2002
- remember how bad you wanted to see Star
  Wars: Episode 1?
- that’s how excited you should be for 5.10
- but it won’t suck (no POD race scene)

                                        perl51000delta
Lexicascopasmartwhat?




                  perl51000delta
Lexicascopasmartwhat?

- lexically scoped user pragmata!




                                    perl51000delta
Lexicascopasmartwhat?

- lexically scoped user pragmata!
- pluggable regex compilation engines!



                                         perl51000delta
Lexicascopasmartwhat?

- lexically scoped user pragmata!
- pluggable regex compilation engines!
- trie-based non-recursive pattern matching!


                                        perl51000delta
Lexicascopasmartwhat?

- lexically scoped user pragmata!
- pluggable regex compilation engines!
- trie-based non-recursive pattern matching!
- thread-safe weak refkey hashes!

                                        perl51000delta
Yes, You Care




                perl51000delta
Yes, You Care

- Not everything in 5.10 is esoteric.




                                        perl51000delta
Yes, You Care

- Not everything in 5.10 is esoteric.
- Not everything in 5.10 is for gurus.



                                         perl51000delta
Yes, You Care

- Not everything in 5.10 is esoteric.
- Not everything in 5.10 is for gurus.
- Not everything in 5.10 is for C programmers.


                                       perl51000delta
Yes, You Care

- Not everything in 5.10 is esoteric.
- Not everything in 5.10 is for gurus.
- Not everything in 5.10 is for C programmers.
- Not everything in 5.10 is super advanced.

                                       perl51000delta
First: A Warning




                   feature
First: A Warning
- 5.10 is backwards compatible




                                 feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators




                                        feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default



                                        feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default
-   use feature ‘mtfnpy’;




                                        feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default
-   use feature ‘mtfnpy’;

-   use 5.010;




                                        feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default
-   use feature ‘mtfnpy’;

-   use 5.010;

- read the perldoc
                                        feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default
-   use feature ‘mtfnpy’;

-   use 5.010;

- read the perldoc                I’m a perldoc
                                       ref!
                                              feature
First: A Warning
- 5.10 is backwards compatible
- but adds new keywords and operators
- they’re not enabled by default
-   use feature ‘mtfnpy’;

-   use 5.010;

- read the perldoc
                                        feature
say what
say $what


- new built-in, say
- it’s like print
- but it adds a newline for you

                                  perlfunc
say $what




            perlfunc
say $what

print “Hello, world!n”;




                           perlfunc
say $what

print “Hello, world!n”;


print “$messagen”;




                           perlfunc
say $what

print “Hello, world!n”;


print “$messagen”;


print “$_n” for @lines;


                           perlfunc
say $what

print “Hello, world!n”;
say “Hello, world!”;
print “$messagen”;


print “$_n” for @lines;


                           perlfunc
say $what

print “Hello, world!n”;
say “Hello, world!”;
print “$messagen”;
say $message;
print “$_n” for @lines;


                           perlfunc
say $what

print “Hello, world!n”;
say “Hello, world!”;
print “$messagen”;
say $message;
print “$_n” for @lines;
say for @lines;

                           perlfunc
truth and definedness
truth and definedness




                        perlop
truth and definedness
sub record_sale {




                          perlop
truth and definedness
sub record_sale {
  my ($product, $amount) = @_;




                             perlop
truth and definedness
sub record_sale {
  my ($product, $amount) = @_;

  $amount ||= $product->cost;




                                perlop
truth and definedness
sub record_sale {
  my ($product, $amount) = @_;

  $amount ||= $product->cost;

  ...



                                perlop
truth and definedness
sub record_sale {
  my ($product, $amount) = @_;

    $amount ||= $product->cost;

    ...
}


                                  perlop
truth and definedness
sub record_sale {
  my ($product, $amount) = @_;

    $amount = defined $amount
            ? $amount
            : $product->cost;

    ...
}

                                perlop
truth and definedness
sub record_sale {
  my ($product, $amount) = @_;

    $amount ||= $product->cost;

    ...
}


                                  perlop
truth and definedness
sub record_sale {
  my ($product, $amount) = @_;

    $amount ||= $product->cost;

    ...
}


                                  perlop
the new OR operator
sub record_sale {
  my ($product, $amount) = @_;

    $amount //= $product->cost;

    ...
}


                                  perlop
the new OR operator


$setting = defined $given
         ? $given
         : $default;




                            perlop
the new OR operator

$setting = $given;
unless (defined $setting) {
  $setting = $default;
}




                              perlop
the new OR operator


$setting = $given || $default;




                             perlop
the new OR operator


$setting = $given // $default;




                             perlop
keeping state
State Variables
$lines_left = 100;

sub read_line {
  die “trial period expired”
    unless $lines_left-- > 0;
  ...
}


                                perlsub
State Variables
my $lines_left = 100;

sub read_line {
  die “trial period expired”
    unless $lines_left-- > 0;
  ...
}


                                perlsub
State Variables
{
    my $lines_left = 100;

    sub read_line {
      die “trial period expired”
       unless $lines_left-- > 0;
      ...
    }
}

                               perlsub
State Variables
package Trial::Period;
sub new {
  my ($class, $arg) = @_;
  my $guts = {
    lines_left => $arg->{lines},
    error_msg => $arg->{error},
  };
  return bless $guts => $class;
}                                  my $LINES = 100;
                                   my $ERROR = “sorry, trial period over”;
sub consume_line {                 my $TRIAL = Trial::Period->new({
  my ($self) = @_;                   lines => $LINES,
  $self->{lines_left}--;             error => $ERROR,
}                                  });

sub lines_left {                   sub read_line {
  my ($self) = @_;                   $TRIAL->assert_lines_left;
  return $self->{lines_left};        ...
}                                  }

sub assert_lines_left {
   my ($self) = @_;
   unless ($self->lines_left) {
     die $self->{error_msg};
   }
}
1;




                                                                             perlsub
State Variables
{
    my $lines_left = 100;

    sub read_line {
      die “trial period expired”
       unless $lines_left-- > 0;
      ...
    }
}

                               perlsub
State Variables

sub read_line {
  state $lines_left = 100;
  die “trial period expired”
    unless $lines_left-- > 0;
  ...
}


                                perlsub
-x stacking
Stackable File Tests
if (
  -f $file
  and -w $file
  and -z $file
) {
  unlink $file;
}


                          perlfunc
Stackable File Tests

if (
  -f $file and -w _ and -z _
) {
  unlink $file;
}



                               perlfunc
Stackable File Tests


if (-f -w -z $file) {
  unlink $file;
}




                          perlfunc
smart matching
Smart Matching




                 perlsyn
Smart Matching

- a new kind of comparison operator




                                      perlsyn
Smart Matching

- a new kind of comparison operator
- its behavior depends on its inputs



                                       perlsyn
Smart Matching

- a new kind of comparison operator
- its behavior depends on its inputs
- “if these two things match...”


                                       perlsyn
Smart Matching

- a new kind of comparison operator
- its behavior depends on its inputs
- “if these two things match...”
- hard to tell, easy to show...

                                       perlsyn
Smart Matching




                 perlsyn
Smart Matching
if ($foo ~~ undef)   { ... }




                           perlsyn
Smart Matching
   if ($foo ~~ undef) { ... }
elsif ($foo ~~ @array) { ... }




                             perlsyn
Smart Matching
   if ($foo ~~ undef) { ... }
elsif ($foo ~~ @array) { ... }
elsif ($foo ~~ $code) { ... }




                             perlsyn
Smart Matching
   if   ($foo   ~~   undef)    {   ...   }
elsif   ($foo   ~~   @array)   {   ...   }
elsif   ($foo   ~~   $code)    {   ...   }
elsif   ($foo   ~~   %hash)    {   ...   }




                                         perlsyn
Smart Matching
   if   ($foo   ~~   undef)    {   ...   }
elsif   ($foo   ~~   @array)   {   ...   }
elsif   ($foo   ~~   $code)    {   ...   }
elsif   ($foo   ~~   %hash)    {   ...   }
elsif   ($foo   ~~   qr/re/)   {   ...   }




                                         perlsyn
Smart Matching
   if   ($foo   ~~   undef)    {   ...   }
elsif   ($foo   ~~   @array)   {   ...   }
elsif   ($foo   ~~   $code)    {   ...   }
elsif   ($foo   ~~   %hash)    {   ...   }
elsif   ($foo   ~~   qr/re/)   {   ...   }
elsif   ($foo   ~~   $bar)     {   ...   }



                                         perlsyn
Smart Matching
   if   ($foo   ~~   undef)    {   ...   }
elsif   ($foo   ~~   @array)   {   ...   }
elsif   ($foo   ~~   $code)    {   ...   }
elsif   ($foo   ~~   %hash)    {   ...   }
elsif   ($foo   ~~   qr/re/)   {   ...   }
elsif   ($foo   ~~   $bar)     {   ...   }
else                           {   ...   }


                                         perlsyn
Smart Matching
given ($foo) {
  when (undef)    {   ...   }
  when (@array)   {   ...   }
  when ($code)    {   ...   }
  when (%hash)    {   ...   }
  when (qr/re/)   {   ...   }
  when ($bar)     {   ...   }
  default         {   ...   }
}

                                perlsyn
Smart Matching
   if   ($foo   ~~   undef)    {   ...   }
elsif   ($foo   ~~   @array)   {   ...   }
elsif   ($foo   ~~   $code)    {   ...   }
elsif   ($foo   ~~   %hash)    {   ...   }
elsif   ($foo   ~~   qr/re/)   {   ...   }
elsif   ($foo   ~~   $bar)     {   ...   }
else                           {   ...   }


                                         perlsyn
Smart Matching
   if   ($foo   ~~   undef)    {   ...   }
elsif   ($foo   ~~   $array)   {   ...   }
elsif   ($foo   ~~   $code)    {   ...   }
elsif   ($foo   ~~   $hash)    {   ...   }
elsif   ($foo   ~~   qr/re/)   {   ...   }
elsif   ($foo   ~~   $bar)     {   ...   }
else                           {   ...   }


                                         perlsyn
Smart Matching



my $test;

                 perlsyn
Smart Matching
given ($foo) {
  when (undef)     {   ...   }
  when ($aref)     {   ...   }
  when ($code)     {   ...   }
  when ($href)     {   ...   }
  when ($regex)    {   ...   }
  when ($object)   {   ...   }
  default          {   ...   }
}

                                 perlsyn
Smart Matching
given ($foo) {
  when ($test_1)   {   ...   }
  when ($test_2)   {   ...   }
  when ($test_3)   {   ...   }
  when ($test_4)   {   ...   }
  when ($test_5)   {   ...   }
  when ($test_6)   {   ...   }
  default          {   ...   }
}

                                 perlsyn
Smart Matching




                 perlsyn
Smart Matching

@want = @have->where($test)




                              perlsyn
Smart Matching

 @want = @have->where($test)

@want = @have->where(sub{ …… })




                               perlsyn
Smart Matching

 @want = @have->where($test)

@want = @have->where(sub{ …… })

@want = @have->where(qr/.../sm)




                               perlsyn
Smart Matching

 @want = @have->where($test)

@want = @have->where(sub{ …… })

@want = @have->where(qr/.../sm)

@want = @have->where([ 1,2,3 ])


                               perlsyn
Smart Matching




                 perlsyn
Smart Matching
sub where {




                           perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;




                             perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test eq ‘ARRAY’)   {




                                 perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test eq ‘ARRAY’) {
   my %known = map {$_=>1} @$test;




                                     perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test eq ‘ARRAY’) {
   my %known = map {$_=>1} @$test;
   return grep { $known{$_} } @$array;




                                         perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test eq ‘ARRAY’) {
   my %known = map {$_=>1} @$test;
   return grep { $known{$_} } @$array;
 }




                                         perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test   eq ‘ARRAY’) {
   my %known =   map {$_=>1} @$test;
   return grep   { $known{$_} } @$array;
 }
 if (ref $test   eq ‘Regexp’) {




                                           perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test   eq ‘ARRAY’) {
   my %known =   map {$_=>1} @$test;
   return grep   { $known{$_} } @$array;
 }
 if (ref $test   eq ‘Regexp’) {
   return grep   { $_ =~ $test } @$array;




                                            perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test   eq ‘ARRAY’) {
   my %known =   map {$_=>1} @$test;
   return grep   { $known{$_} } @$array;
 }
 if (ref $test   eq ‘Regexp’) {
   return grep   { $_ =~ $test } @$array;
 }




                                            perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test   eq ‘ARRAY’) {
   my %known =   map {$_=>1} @$test;
   return grep   { $known{$_} } @$array;
 }
 if (ref $test   eq ‘Regexp’) {
   return grep   { $_ =~ $test } @$array;
 }
 if (ref $test   eq ‘CODE’) {




                                            perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test   eq ‘ARRAY’) {
   my %known =   map {$_=>1} @$test;
   return grep   { $known{$_} } @$array;
 }
 if (ref $test   eq ‘Regexp’) {
   return grep   { $_ =~ $test } @$array;
 }
 if (ref $test   eq ‘CODE’) {
   return grep   { $test->($_) } @$array;




                                            perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test   eq ‘ARRAY’) {
   my %known =   map {$_=>1} @$test;
   return grep   { $known{$_} } @$array;
 }
 if (ref $test   eq ‘Regexp’) {
   return grep   { $_ =~ $test } @$array;
 }
 if (ref $test   eq ‘CODE’) {
   return grep   { $test->($_) } @$array;
 }




                                            perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

 if (ref $test   eq ‘ARRAY’) {
   my %known =   map {$_=>1} @$test;
   return grep   { $known{$_} } @$array;
 }
 if (ref $test   eq ‘Regexp’) {
   return grep   { $_ =~ $test } @$array;
 }
 if (ref $test   eq ‘CODE’) {
   return grep   { $test->($_) } @$array;
 }

 die “invalid test”




                                            perlsyn
Smart Matching
sub where {
  my ($array, $test) = @_;

    if (ref $test   eq ‘ARRAY’) {
      my %known =   map {$_=>1} @$test;
      return grep   { $known{$_} } @$array;
    }
    if (ref $test   eq ‘Regexp’) {
      return grep   { $_ =~ $test } @$array;
    }
    if (ref $test   eq ‘CODE’) {
      return grep   { $test->($_) } @$array;
    }

    die “invalid test”
}


                                               perlsyn
Smart Matching


sub where {
  my ($array, $test) = @_;
  grep { $_ ~~ $test } @$array;
}




                                  perlsyn
Smart Matching
  SmartMatch::Sugar




                      perlsyn
Smart Matching
      SmartMatch::Sugar

@want = @have->where( hash )




                               perlsyn
Smart Matching
       SmartMatch::Sugar

@want = @have->where( hash )

@want = @have->where( class )




                                perlsyn
Smart Matching
        SmartMatch::Sugar

 @want = @have->where( hash )

 @want = @have->where( class )

@want = @have->where(isa(‘Foo’))




                                 perlsyn
unknown undefined
Better Error Message(s)

$str = “Greetings, $name. Your last
login was $last. It is now $time.”;




                                 perldiag
Better Error Message(s)

$str = “Greetings, $name. Your last
login was $last. It is now $time.”;




Use of uninitialized value in
concatenation (.) or string at
hello.plx line 9.


                                 perldiag
Better Error Message(s)

$str = “Greetings, $name. Your last
login was $last. It is now $time.”;




Use of uninitialized value $time in
concatenation (.) or string at
hello.plx line 9.


                                  perldiag
inside-out objects
Inside-Out Objects




              Hash::Util::FieldHash
Inside-Out Objects
- traditional objects are a hashref




                                      Hash::Util::FieldHash
Inside-Out Objects
- traditional objects are a hashref
  - look up attrs in the obj itself by attr name




                                   Hash::Util::FieldHash
Inside-Out Objects
- traditional objects are a hashref
  - look up attrs in the obj itself by attr name
- inside-out objects are content-free refs



                                   Hash::Util::FieldHash
Inside-Out Objects
- traditional objects are a hashref
  - look up attrs in the obj itself by attr name
- inside-out objects are content-free refs
  - look up attrs in an external hash by obj id

                                   Hash::Util::FieldHash
Inside-Out Objects
- traditional objects are a hashref
  - look up attrs in the obj itself by attr name
- inside-out objects are content-free refs
  - look up attrs in an external hash by obj id
- there are complications for inside-out objects
                                   Hash::Util::FieldHash
Inside-Out Objects
sub size {
  my $self = shift;

    if (@_) {
      return $self->{size} = shift;
    } else {
      return $self->{size};
    }
}


                          Hash::Util::FieldHash
Inside-Out Objects
my %size;
sub size {
  my $self = shift;

    if (@_) {
      return $size{ $self } = shift;
    } else {
      return $size{ $self };
    }
}

                          Hash::Util::FieldHash
Inside-Out Objects
my %size;
sub size {
  my $self = shift;
  my $id   = refaddr $self;

    if (@_) {
      return $size{ $id } = shift;
    } else {
      return $size{ $id };
    }
}

                            Hash::Util::FieldHash
Inside-Out Objects
my %size;
sub size {
  my $self = shift;
  my $id   = refaddr $self;

    if (@_) {
      return $size{ $id } = shift;
    } else {
      return $size{ $id };
    }
}

sub DESTROY {
  my $id = refaddr $_[0];
  delete $size{ $id };
}



                                     Hash::Util::FieldHash
Inside-Out Objects
my %size;                            sub CLONE {
sub size {                             my $class = shift;
  my $self = shift;
  my $id   = refaddr $self;            my @properties = map { values %$_ }
                                     values %PROP_DATA_FOR;
    if (@_) {
      return $size{ $id } = shift;       for my $old_id ( keys %OBJ ) {
    } else {
      return $size{ $id };                   my $object = $OBJ{ $old_id };
    }                                        my $new_id = refaddr $object;
}
                                             for my $prop ( @properties ) {
sub DESTROY {                                  next unless exists $prop->{ $old };
  my $id = refaddr $_[0];                      $prop->{ $new } = $prop->{ $old };
  delete $size{ $id };                         delete $prop->{ $old };
}                                            }

                                             weaken ( $OBJ{ $new } = $object );
                                             delete $OBJ{ $old };
                                         }
                                     }




                                                            Hash::Util::FieldHash
Inside-Out Objects
my %OBJECT_REGISTRY;                   sub CLONE {
my %size;                                my $class = shift;
sub size {
  my $self = shift;                      my @properties = map { values %$_ }
  my $id   = refaddr $self;            values %PROP_DATA_FOR;

    $self->register_object;                for my $old_id ( keys %OBJECT_REGISTRY )
                                       {
    if (@_) {
      return $size{ $self } = shift;       my $object =
    } else {                           $OBJECT_REGISTRY{ $old_id };
      return $size{ $self };               my $new_id = refaddr $object;
    }
}                                          for my $prop ( @properties ) {
                                             next unless exists $prop-
sub DESTROY {                          >{ $old_id };
  my $id = refaddr $_[0];                    $prop->{ $new_id } = $prop-
  delete $size{ $id };                 >{ $old_id };
  delete $OBJECT_REGISTRY{ $id };            delete $prop->{ $old_id };
}                                          }

sub register_object {                      weaken ( $OBJECT_REGISTRY{ $new_id } =
  my ($self) = @_;                     $object );
  my $id = refaddr $self;                  delete $OBJECT_REGISTRY{ $old_id };
  $OBJECT_REGISTRY{ $id } = $self;       }
}                                      }




                                                            Hash::Util::FieldHash
Field Hashes




           Hash::Util::FieldHash
Field Hashes

- they’re just like hashes




                             Hash::Util::FieldHash
Field Hashes

- they’re just like hashes
- objects as keys become object ids



                                  Hash::Util::FieldHash
Field Hashes

- they’re just like hashes
- objects as keys become object ids
- but get destroyed and cloned

                                  Hash::Util::FieldHash
Field Hashes
my %size;
sub size {
  my $self = shift;

    if (@_) {
      return $size{ $self } = shift;
    } else {
      return $size{ $self };
    }
}

                          Hash::Util::FieldHash
Field Hashes
fieldhash my %size;
sub size {
  my $self = shift;

    if (@_) {
      return $size{ $self } = shift;
    } else {
      return $size{ $self };
    }
}

                          Hash::Util::FieldHash
Field Hashes
{
    fieldhash my %size;
    sub size {
      my $self = shift;
      if (@_) {
        return $size{ $self } = shift;
      } else {
        return $size{ $self };
      }
    }
}

                              Hash::Util::FieldHash
Field Hashes
sub size {
  my $self = shift;
  fieldhash state %size;

    if (@_) {
      return $size{ $self } = shift;
    } else {
      return $size{ $self };
    }
}

                           Hash::Util::FieldHash
lexical topic
(topic is how you say $_)
Lexical Topic
for (@lines) {
  chomp;
  next if /^#/;
  next unless length;
  s/a/b/;
  sanity_check;
  say;
}

                        perlvar
Lexical Topic
for my $line (@lines) {
  chomp $line;
  next if $line ~~ /^#/;
  next unless length $line;
  $line =~ s/a/b/;
  sanity_check($line);
  say $line;
}

                              perlvar
Lexical Topic
for my $_ (@lines) {
  chomp;
  next if /^#/;
  next unless length;
  s/a/b/;
  sanity_check;
  say;
}

                        perlvar
Regex
named captures
Regex: Named Captures




                        perlre
Regex: Named Captures

- find matches by name, not position




                                       perlre
Regex: Named Captures

- find matches by name, not position
- avoid the dreaded$1




                                       perlre
Regex: Named Captures

- find matches by name, not position
- avoid the dreaded $1


- no longer second to Python or .Net!

                                        perlre
Regex: Named Captures


# our hypothetical format

section:property = value




                            perlre
Regex: Named Captures

$line ~~ /(w+):(w+) = (w+)/;

$name = $2;
$value = $3;




                                  perlre
Regex: Named Captures

$lhs_re = qr/(w+):(w+)/;
$rhs_re = qr/(w+)/;

$line ~~ /$lhs_re = $rhs_re/;

$name = $2;
$value = $3;



                                perlre
Regex: Named Captures

$line ~~ /$lhs_re = $rhs_re/;

$name = $2;
$value = $3;




                                perlre
Regex: Named Captures

$line ~~ /$lhs_re = $rhs_re/;

$name = $+{ name };
$value = $+{ value };




                                perlre
Regex: Named Captures


$lhs_re = qr/(w+):(w+)/;
$rhs_re = qr/(w+)/;




                             perlre
Regex: Named Captures


$lhs_re = qr/(w+):(?<name>w+)/;
$rhs_re = qr/(?<value>w+)/;




                                    perlre
better backrefs
Regex: Backreference


 m{< (w+) > .+ < /1 > }x




                             perlre
Regex: Backreference


 m{< (w+) > .+ < /1 > }x




                             perlre
Regex: Backreference



      10
                       perlre
Regex: Backreference


  qr{(d)10}


                       perlre
Regex: Backreference


qr{ (d) 1 0}x


                       perlre
Regex: Backreference


 m{< (w+) > .+ < /1 > }x




                             perlre
Regex: Backreference


m{< (w+) > .+ < /g{1} > }x




                               perlre
Regex: Backreference



      10
                       perlre
Regex: Backreference



   g{10}
                       perlre
Regex: Backreference


  qr{(d)10}


                       perlre
Regex: Backreference


qr{(d)g{1}0}


                       perlre
Regex: Backreference


qr{(d)g{-1}0}


                       perlre
Regex: Backreference
qr{
   (?<digit>d)
   g{digit}
   0
}x
                       perlre
Regex: Exit Strategy
my $wtf_re = qr{
xffn015()]*(?:[^x80-xff][^x80-xffn015()]*)*))[^x80-xf
fn015()]*)*)[040t]*)*(?:(?:[^(040)<>@,;:”.[]000-037x80-x
ff]+(?![^(040)<>@,;:”.[]000-037x80-xff])|”[^x80-xffn015
“]*(?:[^x80-xff][^x80-xffn015”]*)*”)[040t]*(?:([^x80-
xffn015()]*(?:(?:[^x80-xff]|([^x80-xffn015()]*(?:[^x80
-xff][^x80-xffn015()]*)*))[^x80-xffn015()]*)*)[040t]*
)*(?:.[040t]*(?:([^x80-xffn015()]*(?:(?:[^x80-xff]|([^
x80-xffn015()]*(?:[^x80-xff][^x80-xffn015()]*)*))[^
x80-xffn015()]*)*)[040t]*)*(?:[^(040)<>@,;:”.[]000-037x8
0-xff]+(?![^(040)<>@,;:”.[]000-037x80-xff])|”[^x80-xffn
015”]*(?:[^x80-xff][^x80-xffn015”]*)*”)[040t]*(?:([^x
80-xffn015()]*(?:(?:[^x80-xff]|([^x80-xffn015()]*(?:[^
x80-xff][^x80-xffn015()]*)*))[^x80-xffn015()]*)*)[040
t]*)*)*@[040t]*(?:([^x80-xffn015()]*(?:(?:[^x80-xff]|([
^x80-xffn015()]*(?:[^x80-xff][^x80-xffn015()]*)*))[^
x80-xffn015()]*)*)[040t]*)*(?:[^(040)<>@,;:”.[]000-037
x80-xff]+(?![^(040)<>@,;:”.[]000-037x80-xff])|[(?:[^x80-
xffn015[]]|[^x80-xff])*])[040t]*(?:([^x80-xffn015()
]*(?:(?:[^x80-xff]|([^x80-xffn015()]*(?:[^x80-xff][^
x80-xffn015()]*)*))[^x80-xffn015()]*)*)[040t]*)*(?:.[04
};




                                                                         wtf
Regex: Backreference


if ($str =~ $wtf_re) {
  ...
}



                       perlop
Regex: Backreference


if ($str ~~ $wtf_re) {
  ...
}



                       perlop
lexically scoped alternate
trie-based reentrant user-
 defined regex pragmata
flexible regex
Alternate Regex Engines




                      perlreapi
Alternate Regex Engines


- lets you change how regex work



                                   perlreapi
Alternate Regex Engines


- lets you change how regex work
- but not how you use them ( ,
                            =~ s///, etc)




                                            perlreapi
Alternate Regex Engines




                  re::engine::POSIX
Alternate Regex Engines


egrep -r -l PATTERN DIR




                          re::engine::POSIX
Alternate Regex Engines

my $regex = qr{ ... };

my @files = $find->file->in( $root );

say for grep { slurp ~~ $re } @files;




                                 re::engine::POSIX
Alternate Regex Engines




                  re::engine::POSIX
Alternate Regex Engines


egrep -r -l ‘.+?’ DIR




                        re::engine::POSIX
Alternate Regex Engines

my $regex = qr{ ... };

my @files = $find->file->in( $root );

say for grep { slurp ~~ $re } @files;




                                 re::engine::POSIX
Alternate Regex Engines

use re::engine::POSIX;

my $regex = qr{ ... };

my @files = $find->file->in( $root );

say for grep { slurp ~~ $re } @files;




                                 re::engine::POSIX
Alternate Regex Engines

use re::engine::POSIX;

my $regex = qr{ ... }x;

my @files = $find->file->in( $root );

say for grep { slurp ~~ $re } @files;




                                 re::engine::POSIX
http://www.perl.org/get.html
Any questions?

Mais conteúdo relacionado

Mais procurados

Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell ScriptingMustafa Qasim
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout Rachel Andrew
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation platico_dev
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++PRINCE KUMAR
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arraysKumar
 
C++ Function
C++ FunctionC++ Function
C++ FunctionHajar
 
Celery - A Distributed Task Queue
Celery - A Distributed Task QueueCelery - A Distributed Task Queue
Celery - A Distributed Task QueueDuy Do
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Codemotion
 

Mais procurados (20)

Unix Shell Scripting
Unix Shell ScriptingUnix Shell Scripting
Unix Shell Scripting
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
PHP POWERPOINT SLIDES
PHP POWERPOINT SLIDESPHP POWERPOINT SLIDES
PHP POWERPOINT SLIDES
 
CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout CSS Day: CSS Grid Layout
CSS Day: CSS Grid Layout
 
Php technical presentation
Php technical presentationPhp technical presentation
Php technical presentation
 
Ruby Presentation
Ruby Presentation Ruby Presentation
Ruby Presentation
 
Php basics
Php basicsPhp basics
Php basics
 
Python-Inheritance.pptx
Python-Inheritance.pptxPython-Inheritance.pptx
Python-Inheritance.pptx
 
Polymorphism Using C++
Polymorphism Using C++Polymorphism Using C++
Polymorphism Using C++
 
PHP Unit 4 arrays
PHP Unit 4 arraysPHP Unit 4 arrays
PHP Unit 4 arrays
 
Unary operator overloading
Unary operator overloadingUnary operator overloading
Unary operator overloading
 
Python: Polymorphism
Python: PolymorphismPython: Polymorphism
Python: Polymorphism
 
Flask Basics
Flask BasicsFlask Basics
Flask Basics
 
PHP
PHPPHP
PHP
 
C++ Function
C++ FunctionC++ Function
C++ Function
 
List in Python
List in PythonList in Python
List in Python
 
C if else
C if elseC if else
C if else
 
Celery - A Distributed Task Queue
Celery - A Distributed Task QueueCelery - A Distributed Task Queue
Celery - A Distributed Task Queue
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
 
php
phpphp
php
 

Destaque

Asynchronous programming with AnyEvent
Asynchronous programming with AnyEventAsynchronous programming with AnyEvent
Asynchronous programming with AnyEventTatsuhiko Miyagawa
 
New Zealand
New ZealandNew Zealand
New ZealandSchool
 
The Seven Deadly Sins of Bioinformatics
The Seven Deadly Sins of BioinformaticsThe Seven Deadly Sins of Bioinformatics
The Seven Deadly Sins of BioinformaticsDuncan Hull
 
KohaCon11: Integrating Koha with RFID system
KohaCon11: Integrating Koha with RFID systemKohaCon11: Integrating Koha with RFID system
KohaCon11: Integrating Koha with RFID systemDobrica Pavlinušić
 
Let's hack cheap hardware 2016 edition
Let's hack cheap hardware 2016 editionLet's hack cheap hardware 2016 edition
Let's hack cheap hardware 2016 editionDobrica Pavlinušić
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?acme
 

Destaque (6)

Asynchronous programming with AnyEvent
Asynchronous programming with AnyEventAsynchronous programming with AnyEvent
Asynchronous programming with AnyEvent
 
New Zealand
New ZealandNew Zealand
New Zealand
 
The Seven Deadly Sins of Bioinformatics
The Seven Deadly Sins of BioinformaticsThe Seven Deadly Sins of Bioinformatics
The Seven Deadly Sins of Bioinformatics
 
KohaCon11: Integrating Koha with RFID system
KohaCon11: Integrating Koha with RFID systemKohaCon11: Integrating Koha with RFID system
KohaCon11: Integrating Koha with RFID system
 
Let's hack cheap hardware 2016 edition
Let's hack cheap hardware 2016 editionLet's hack cheap hardware 2016 edition
Let's hack cheap hardware 2016 edition
 
What's new in Perl 5.10?
What's new in Perl 5.10?What's new in Perl 5.10?
What's new in Perl 5.10?
 

Semelhante a Perl 5.10 for People Who Aren't Totally Insane

What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16Ricardo Signes
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perltinypigdotcom
 
Perl 5.14 for Pragmatists
Perl 5.14 for PragmatistsPerl 5.14 for Pragmatists
Perl 5.14 for PragmatistsRicardo Signes
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it2shortplanks
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl styleBo Hua Yang
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In PerlKang-min Liu
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl TechniquesDave Cross
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Kang-min Liu
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.Workhorse Computing
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlordsheumann
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)osfameron
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern PerlDave Cross
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.VimLin Yo-An
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perldaoswald
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottO'Reilly Media
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinosbrian d foy
 

Semelhante a Perl 5.10 for People Who Aren't Totally Insane (20)

What's New in Perl? v5.10 - v5.16
What's New in Perl?  v5.10 - v5.16What's New in Perl?  v5.10 - v5.16
What's New in Perl? v5.10 - v5.16
 
Writing Maintainable Perl
Writing Maintainable PerlWriting Maintainable Perl
Writing Maintainable Perl
 
Perl 5.14 for Pragmatists
Perl 5.14 for PragmatistsPerl 5.14 for Pragmatists
Perl 5.14 for Pragmatists
 
Perl Sucks - and what to do about it
Perl Sucks - and what to do about itPerl Sucks - and what to do about it
Perl Sucks - and what to do about it
 
Programming in perl style
Programming in perl styleProgramming in perl style
Programming in perl style
 
Php Basic
Php BasicPhp Basic
Php Basic
 
Basic PHP
Basic PHPBasic PHP
Basic PHP
 
Good Evils In Perl
Good Evils In PerlGood Evils In Perl
Good Evils In Perl
 
Advanced Perl Techniques
Advanced Perl TechniquesAdvanced Perl Techniques
Advanced Perl Techniques
 
Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)Good Evils In Perl (Yapc Asia)
Good Evils In Perl (Yapc Asia)
 
The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.The $path to knowledge: What little it take to unit-test Perl.
The $path to knowledge: What little it take to unit-test Perl.
 
I, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 OverlordsI, For One, Welcome Our New Perl6 Overlords
I, For One, Welcome Our New Perl6 Overlords
 
Unit Testing Lots of Perl
Unit Testing Lots of PerlUnit Testing Lots of Perl
Unit Testing Lots of Perl
 
Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)Functional Pearls 4 (YAPC::EU::2009 remix)
Functional Pearls 4 (YAPC::EU::2009 remix)
 
Introduction to Modern Perl
Introduction to Modern PerlIntroduction to Modern Perl
Introduction to Modern Perl
 
Perl.Hacks.On.Vim
Perl.Hacks.On.VimPerl.Hacks.On.Vim
Perl.Hacks.On.Vim
 
Cleancode
CleancodeCleancode
Cleancode
 
Whatsnew in-perl
Whatsnew in-perlWhatsnew in-perl
Whatsnew in-perl
 
Dealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter ScottDealing with Legacy Perl Code - Peter Scott
Dealing with Legacy Perl Code - Peter Scott
 
Advanced modulinos
Advanced modulinosAdvanced modulinos
Advanced modulinos
 

Mais de Ricardo Signes

Perl 5: Today, Tomorrow, and Christmas
Perl 5: Today, Tomorrow, and ChristmasPerl 5: Today, Tomorrow, and Christmas
Perl 5: Today, Tomorrow, and ChristmasRicardo Signes
 
Dist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN DistributionsDist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN DistributionsRicardo Signes
 
Perl 5.12 for Everyday Use
Perl 5.12 for Everyday UsePerl 5.12 for Everyday Use
Perl 5.12 for Everyday UseRicardo Signes
 
Antediluvian Unix: A Guide to Unix Fundamentals
Antediluvian Unix: A Guide to Unix FundamentalsAntediluvian Unix: A Guide to Unix Fundamentals
Antediluvian Unix: A Guide to Unix FundamentalsRicardo Signes
 
Writing Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::CmdWriting Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::CmdRicardo Signes
 
Crafting Custom Interfaces with Sub::Exporter
Crafting Custom Interfaces with Sub::ExporterCrafting Custom Interfaces with Sub::Exporter
Crafting Custom Interfaces with Sub::ExporterRicardo Signes
 
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!Ricardo Signes
 

Mais de Ricardo Signes (9)

Perl 5: Today, Tomorrow, and Christmas
Perl 5: Today, Tomorrow, and ChristmasPerl 5: Today, Tomorrow, and Christmas
Perl 5: Today, Tomorrow, and Christmas
 
Dist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN DistributionsDist::Zilla - Maximum Overkill for CPAN Distributions
Dist::Zilla - Maximum Overkill for CPAN Distributions
 
Perl 5.12 for Everyday Use
Perl 5.12 for Everyday UsePerl 5.12 for Everyday Use
Perl 5.12 for Everyday Use
 
i &lt;3 email
i &lt;3 emaili &lt;3 email
i &lt;3 email
 
Dist::Zilla
Dist::ZillaDist::Zilla
Dist::Zilla
 
Antediluvian Unix: A Guide to Unix Fundamentals
Antediluvian Unix: A Guide to Unix FundamentalsAntediluvian Unix: A Guide to Unix Fundamentals
Antediluvian Unix: A Guide to Unix Fundamentals
 
Writing Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::CmdWriting Modular Command-line Apps with App::Cmd
Writing Modular Command-line Apps with App::Cmd
 
Crafting Custom Interfaces with Sub::Exporter
Crafting Custom Interfaces with Sub::ExporterCrafting Custom Interfaces with Sub::Exporter
Crafting Custom Interfaces with Sub::Exporter
 
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
How I Learned to Stop Worrying and Love Email::: The 2007 PEP Talk!!
 

Último

7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...Paul Menig
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdfRenandantas16
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayNZSG
 
Vip Dewas Call Girls #9907093804 Contact Number Escorts Service Dewas
Vip Dewas Call Girls #9907093804 Contact Number Escorts Service DewasVip Dewas Call Girls #9907093804 Contact Number Escorts Service Dewas
Vip Dewas Call Girls #9907093804 Contact Number Escorts Service Dewasmakika9823
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation SlidesKeppelCorporation
 
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130  Available With RoomVIP Kolkata Call Girl Howrah 👉 8250192130  Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Roomdivyansh0kumar0
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Roland Driesen
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth MarketingShawn Pang
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Lviv Startup Club
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear RegressionRavindra Nath Shukla
 
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdfCatalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdfOrient Homes
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.Aaiza Hassan
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Dave Litwiller
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...anilsa9823
 
Socio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptxSocio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptxtrishalcan8
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfPaul Menig
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒anilsa9823
 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Tina Ji
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 

Último (20)

7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...7.pdf This presentation captures many uses and the significance of the number...
7.pdf This presentation captures many uses and the significance of the number...
 
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf0183760ssssssssssssssssssssssssssss00101011 (27).pdf
0183760ssssssssssssssssssssssssssss00101011 (27).pdf
 
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
Nepali Escort Girl Kakori \ 9548273370 Indian Call Girls Service Lucknow ₹,9517
 
It will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 MayIt will be International Nurses' Day on 12 May
It will be International Nurses' Day on 12 May
 
Vip Dewas Call Girls #9907093804 Contact Number Escorts Service Dewas
Vip Dewas Call Girls #9907093804 Contact Number Escorts Service DewasVip Dewas Call Girls #9907093804 Contact Number Escorts Service Dewas
Vip Dewas Call Girls #9907093804 Contact Number Escorts Service Dewas
 
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
Keppel Ltd. 1Q 2024 Business Update  Presentation SlidesKeppel Ltd. 1Q 2024 Business Update  Presentation Slides
Keppel Ltd. 1Q 2024 Business Update Presentation Slides
 
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130  Available With RoomVIP Kolkata Call Girl Howrah 👉 8250192130  Available With Room
VIP Kolkata Call Girl Howrah 👉 8250192130 Available With Room
 
Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...Ensure the security of your HCL environment by applying the Zero Trust princi...
Ensure the security of your HCL environment by applying the Zero Trust princi...
 
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
Tech Startup Growth Hacking 101  - Basics on Growth MarketingTech Startup Growth Hacking 101  - Basics on Growth Marketing
Tech Startup Growth Hacking 101 - Basics on Growth Marketing
 
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
Yaroslav Rozhankivskyy: Три складові і три передумови максимальної продуктивн...
 
Regression analysis: Simple Linear Regression Multiple Linear Regression
Regression analysis:  Simple Linear Regression Multiple Linear RegressionRegression analysis:  Simple Linear Regression Multiple Linear Regression
Regression analysis: Simple Linear Regression Multiple Linear Regression
 
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdfCatalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
Catalogue ONG NƯỚC uPVC - HDPE DE NHAT.pdf
 
M.C Lodges -- Guest House in Jhang.
M.C Lodges --  Guest House in Jhang.M.C Lodges --  Guest House in Jhang.
M.C Lodges -- Guest House in Jhang.
 
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
Enhancing and Restoring Safety & Quality Cultures - Dave Litwiller - May 2024...
 
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
Lucknow 💋 Escorts in Lucknow - 450+ Call Girl Cash Payment 8923113531 Neha Th...
 
Socio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptxSocio-economic-Impact-of-business-consumers-suppliers-and.pptx
Socio-economic-Impact-of-business-consumers-suppliers-and.pptx
 
Grateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdfGrateful 7 speech thanking everyone that has helped.pdf
Grateful 7 speech thanking everyone that has helped.pdf
 
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒VIP Call Girls In Saharaganj ( Lucknow  ) 🔝 8923113531 🔝  Cash Payment (COD) 👒
VIP Call Girls In Saharaganj ( Lucknow ) 🔝 8923113531 🔝 Cash Payment (COD) 👒
 
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
Russian Faridabad Call Girls(Badarpur) : ☎ 8168257667, @4999
 
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Pune Just Call 9907093804 Top Class Call Girl Service Available
 

Perl 5.10 for People Who Aren't Totally Insane

  • 1. Perl 5.10 for people who are not insane
  • 2. Perl 5.10 for people who are not totally insane
  • 3. 5.10 isn’t like 5.8.x perl5100delta
  • 4. 5.10 isn’t like 5.8.x - features only get added in new 5.x releases perl5100delta
  • 5. 5.10 isn’t like 5.8.x - features only get added in new 5.x releases - it’s been 5 years since the last release (5.8) perl5100delta
  • 6. 5.10 is Way Cool perl51000delta
  • 7. 5.10 is Way Cool - no significant new features in Perl since 2002 perl51000delta
  • 8. 5.10 is Way Cool - no significant new features in Perl since 2002 - remember how bad you wanted to see Star Wars: Episode 1? perl51000delta
  • 9. 5.10 is Way Cool - no significant new features in Perl since 2002 - remember how bad you wanted to see Star Wars: Episode 1? - that’s how excited you should be for 5.10 perl51000delta
  • 10. 5.10 is Way Cool - no significant new features in Perl since 2002 - remember how bad you wanted to see Star Wars: Episode 1? - that’s how excited you should be for 5.10 - but it won’t suck (no POD race scene) perl51000delta
  • 11. Lexicascopasmartwhat? perl51000delta
  • 12. Lexicascopasmartwhat? - lexically scoped user pragmata! perl51000delta
  • 13. Lexicascopasmartwhat? - lexically scoped user pragmata! - pluggable regex compilation engines! perl51000delta
  • 14. Lexicascopasmartwhat? - lexically scoped user pragmata! - pluggable regex compilation engines! - trie-based non-recursive pattern matching! perl51000delta
  • 15. Lexicascopasmartwhat? - lexically scoped user pragmata! - pluggable regex compilation engines! - trie-based non-recursive pattern matching! - thread-safe weak refkey hashes! perl51000delta
  • 16. Yes, You Care perl51000delta
  • 17. Yes, You Care - Not everything in 5.10 is esoteric. perl51000delta
  • 18. Yes, You Care - Not everything in 5.10 is esoteric. - Not everything in 5.10 is for gurus. perl51000delta
  • 19. Yes, You Care - Not everything in 5.10 is esoteric. - Not everything in 5.10 is for gurus. - Not everything in 5.10 is for C programmers. perl51000delta
  • 20. Yes, You Care - Not everything in 5.10 is esoteric. - Not everything in 5.10 is for gurus. - Not everything in 5.10 is for C programmers. - Not everything in 5.10 is super advanced. perl51000delta
  • 21. First: A Warning feature
  • 22. First: A Warning - 5.10 is backwards compatible feature
  • 23. First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators feature
  • 24. First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default feature
  • 25. First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; feature
  • 26. First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; feature
  • 27. First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; - read the perldoc feature
  • 28. First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; - read the perldoc I’m a perldoc ref! feature
  • 29. First: A Warning - 5.10 is backwards compatible - but adds new keywords and operators - they’re not enabled by default - use feature ‘mtfnpy’; - use 5.010; - read the perldoc feature
  • 31. say $what - new built-in, say - it’s like print - but it adds a newline for you perlfunc
  • 32. say $what perlfunc
  • 33. say $what print “Hello, world!n”; perlfunc
  • 34. say $what print “Hello, world!n”; print “$messagen”; perlfunc
  • 35. say $what print “Hello, world!n”; print “$messagen”; print “$_n” for @lines; perlfunc
  • 36. say $what print “Hello, world!n”; say “Hello, world!”; print “$messagen”; print “$_n” for @lines; perlfunc
  • 37. say $what print “Hello, world!n”; say “Hello, world!”; print “$messagen”; say $message; print “$_n” for @lines; perlfunc
  • 38. say $what print “Hello, world!n”; say “Hello, world!”; print “$messagen”; say $message; print “$_n” for @lines; say for @lines; perlfunc
  • 41. truth and definedness sub record_sale { perlop
  • 42. truth and definedness sub record_sale { my ($product, $amount) = @_; perlop
  • 43. truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; perlop
  • 44. truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... perlop
  • 45. truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
  • 46. truth and definedness sub record_sale { my ($product, $amount) = @_; $amount = defined $amount ? $amount : $product->cost; ... } perlop
  • 47. truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
  • 48. truth and definedness sub record_sale { my ($product, $amount) = @_; $amount ||= $product->cost; ... } perlop
  • 49. the new OR operator sub record_sale { my ($product, $amount) = @_; $amount //= $product->cost; ... } perlop
  • 50. the new OR operator $setting = defined $given ? $given : $default; perlop
  • 51. the new OR operator $setting = $given; unless (defined $setting) { $setting = $default; } perlop
  • 52. the new OR operator $setting = $given || $default; perlop
  • 53. the new OR operator $setting = $given // $default; perlop
  • 55. State Variables $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } perlsub
  • 56. State Variables my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } perlsub
  • 57. State Variables { my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } } perlsub
  • 58. State Variables package Trial::Period; sub new { my ($class, $arg) = @_; my $guts = { lines_left => $arg->{lines}, error_msg => $arg->{error}, }; return bless $guts => $class; } my $LINES = 100; my $ERROR = “sorry, trial period over”; sub consume_line { my $TRIAL = Trial::Period->new({ my ($self) = @_; lines => $LINES, $self->{lines_left}--; error => $ERROR, } }); sub lines_left { sub read_line { my ($self) = @_; $TRIAL->assert_lines_left; return $self->{lines_left}; ... } } sub assert_lines_left { my ($self) = @_; unless ($self->lines_left) { die $self->{error_msg}; } } 1; perlsub
  • 59. State Variables { my $lines_left = 100; sub read_line { die “trial period expired” unless $lines_left-- > 0; ... } } perlsub
  • 60. State Variables sub read_line { state $lines_left = 100; die “trial period expired” unless $lines_left-- > 0; ... } perlsub
  • 62. Stackable File Tests if ( -f $file and -w $file and -z $file ) { unlink $file; } perlfunc
  • 63. Stackable File Tests if ( -f $file and -w _ and -z _ ) { unlink $file; } perlfunc
  • 64. Stackable File Tests if (-f -w -z $file) { unlink $file; } perlfunc
  • 66. Smart Matching perlsyn
  • 67. Smart Matching - a new kind of comparison operator perlsyn
  • 68. Smart Matching - a new kind of comparison operator - its behavior depends on its inputs perlsyn
  • 69. Smart Matching - a new kind of comparison operator - its behavior depends on its inputs - “if these two things match...” perlsyn
  • 70. Smart Matching - a new kind of comparison operator - its behavior depends on its inputs - “if these two things match...” - hard to tell, easy to show... perlsyn
  • 71. Smart Matching perlsyn
  • 72. Smart Matching if ($foo ~~ undef) { ... } perlsyn
  • 73. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } perlsyn
  • 74. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } perlsyn
  • 75. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } perlsyn
  • 76. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } perlsyn
  • 77. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } perlsyn
  • 78. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } else { ... } perlsyn
  • 79. Smart Matching given ($foo) { when (undef) { ... } when (@array) { ... } when ($code) { ... } when (%hash) { ... } when (qr/re/) { ... } when ($bar) { ... } default { ... } } perlsyn
  • 80. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ @array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ %hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } else { ... } perlsyn
  • 81. Smart Matching if ($foo ~~ undef) { ... } elsif ($foo ~~ $array) { ... } elsif ($foo ~~ $code) { ... } elsif ($foo ~~ $hash) { ... } elsif ($foo ~~ qr/re/) { ... } elsif ($foo ~~ $bar) { ... } else { ... } perlsyn
  • 83. Smart Matching given ($foo) { when (undef) { ... } when ($aref) { ... } when ($code) { ... } when ($href) { ... } when ($regex) { ... } when ($object) { ... } default { ... } } perlsyn
  • 84. Smart Matching given ($foo) { when ($test_1) { ... } when ($test_2) { ... } when ($test_3) { ... } when ($test_4) { ... } when ($test_5) { ... } when ($test_6) { ... } default { ... } } perlsyn
  • 85. Smart Matching perlsyn
  • 86. Smart Matching @want = @have->where($test) perlsyn
  • 87. Smart Matching @want = @have->where($test) @want = @have->where(sub{ …… }) perlsyn
  • 88. Smart Matching @want = @have->where($test) @want = @have->where(sub{ …… }) @want = @have->where(qr/.../sm) perlsyn
  • 89. Smart Matching @want = @have->where($test) @want = @have->where(sub{ …… }) @want = @have->where(qr/.../sm) @want = @have->where([ 1,2,3 ]) perlsyn
  • 90. Smart Matching perlsyn
  • 92. Smart Matching sub where { my ($array, $test) = @_; perlsyn
  • 93. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { perlsyn
  • 94. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; perlsyn
  • 95. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; perlsyn
  • 96. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } perlsyn
  • 97. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { perlsyn
  • 98. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; perlsyn
  • 99. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } perlsyn
  • 100. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { perlsyn
  • 101. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; perlsyn
  • 102. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; } perlsyn
  • 103. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; } die “invalid test” perlsyn
  • 104. Smart Matching sub where { my ($array, $test) = @_; if (ref $test eq ‘ARRAY’) { my %known = map {$_=>1} @$test; return grep { $known{$_} } @$array; } if (ref $test eq ‘Regexp’) { return grep { $_ =~ $test } @$array; } if (ref $test eq ‘CODE’) { return grep { $test->($_) } @$array; } die “invalid test” } perlsyn
  • 105. Smart Matching sub where { my ($array, $test) = @_; grep { $_ ~~ $test } @$array; } perlsyn
  • 106. Smart Matching SmartMatch::Sugar perlsyn
  • 107. Smart Matching SmartMatch::Sugar @want = @have->where( hash ) perlsyn
  • 108. Smart Matching SmartMatch::Sugar @want = @have->where( hash ) @want = @have->where( class ) perlsyn
  • 109. Smart Matching SmartMatch::Sugar @want = @have->where( hash ) @want = @have->where( class ) @want = @have->where(isa(‘Foo’)) perlsyn
  • 111. Better Error Message(s) $str = “Greetings, $name. Your last login was $last. It is now $time.”; perldiag
  • 112. Better Error Message(s) $str = “Greetings, $name. Your last login was $last. It is now $time.”; Use of uninitialized value in concatenation (.) or string at hello.plx line 9. perldiag
  • 113. Better Error Message(s) $str = “Greetings, $name. Your last login was $last. It is now $time.”; Use of uninitialized value $time in concatenation (.) or string at hello.plx line 9. perldiag
  • 115. Inside-Out Objects Hash::Util::FieldHash
  • 116. Inside-Out Objects - traditional objects are a hashref Hash::Util::FieldHash
  • 117. Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name Hash::Util::FieldHash
  • 118. Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name - inside-out objects are content-free refs Hash::Util::FieldHash
  • 119. Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name - inside-out objects are content-free refs - look up attrs in an external hash by obj id Hash::Util::FieldHash
  • 120. Inside-Out Objects - traditional objects are a hashref - look up attrs in the obj itself by attr name - inside-out objects are content-free refs - look up attrs in an external hash by obj id - there are complications for inside-out objects Hash::Util::FieldHash
  • 121. Inside-Out Objects sub size { my $self = shift; if (@_) { return $self->{size} = shift; } else { return $self->{size}; } } Hash::Util::FieldHash
  • 122. Inside-Out Objects my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
  • 123. Inside-Out Objects my %size; sub size { my $self = shift; my $id = refaddr $self; if (@_) { return $size{ $id } = shift; } else { return $size{ $id }; } } Hash::Util::FieldHash
  • 124. Inside-Out Objects my %size; sub size { my $self = shift; my $id = refaddr $self; if (@_) { return $size{ $id } = shift; } else { return $size{ $id }; } } sub DESTROY { my $id = refaddr $_[0]; delete $size{ $id }; } Hash::Util::FieldHash
  • 125. Inside-Out Objects my %size; sub CLONE { sub size { my $class = shift; my $self = shift; my $id = refaddr $self; my @properties = map { values %$_ } values %PROP_DATA_FOR; if (@_) { return $size{ $id } = shift; for my $old_id ( keys %OBJ ) { } else { return $size{ $id }; my $object = $OBJ{ $old_id }; } my $new_id = refaddr $object; } for my $prop ( @properties ) { sub DESTROY { next unless exists $prop->{ $old }; my $id = refaddr $_[0]; $prop->{ $new } = $prop->{ $old }; delete $size{ $id }; delete $prop->{ $old }; } } weaken ( $OBJ{ $new } = $object ); delete $OBJ{ $old }; } } Hash::Util::FieldHash
  • 126. Inside-Out Objects my %OBJECT_REGISTRY; sub CLONE { my %size; my $class = shift; sub size { my $self = shift; my @properties = map { values %$_ } my $id = refaddr $self; values %PROP_DATA_FOR; $self->register_object; for my $old_id ( keys %OBJECT_REGISTRY ) { if (@_) { return $size{ $self } = shift; my $object = } else { $OBJECT_REGISTRY{ $old_id }; return $size{ $self }; my $new_id = refaddr $object; } } for my $prop ( @properties ) { next unless exists $prop- sub DESTROY { >{ $old_id }; my $id = refaddr $_[0]; $prop->{ $new_id } = $prop- delete $size{ $id }; >{ $old_id }; delete $OBJECT_REGISTRY{ $id }; delete $prop->{ $old_id }; } } sub register_object { weaken ( $OBJECT_REGISTRY{ $new_id } = my ($self) = @_; $object ); my $id = refaddr $self; delete $OBJECT_REGISTRY{ $old_id }; $OBJECT_REGISTRY{ $id } = $self; } } } Hash::Util::FieldHash
  • 127. Field Hashes Hash::Util::FieldHash
  • 128. Field Hashes - they’re just like hashes Hash::Util::FieldHash
  • 129. Field Hashes - they’re just like hashes - objects as keys become object ids Hash::Util::FieldHash
  • 130. Field Hashes - they’re just like hashes - objects as keys become object ids - but get destroyed and cloned Hash::Util::FieldHash
  • 131. Field Hashes my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
  • 132. Field Hashes fieldhash my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
  • 133. Field Hashes { fieldhash my %size; sub size { my $self = shift; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } } Hash::Util::FieldHash
  • 134. Field Hashes sub size { my $self = shift; fieldhash state %size; if (@_) { return $size{ $self } = shift; } else { return $size{ $self }; } } Hash::Util::FieldHash
  • 136. (topic is how you say $_)
  • 137. Lexical Topic for (@lines) { chomp; next if /^#/; next unless length; s/a/b/; sanity_check; say; } perlvar
  • 138. Lexical Topic for my $line (@lines) { chomp $line; next if $line ~~ /^#/; next unless length $line; $line =~ s/a/b/; sanity_check($line); say $line; } perlvar
  • 139. Lexical Topic for my $_ (@lines) { chomp; next if /^#/; next unless length; s/a/b/; sanity_check; say; } perlvar
  • 140. Regex
  • 143. Regex: Named Captures - find matches by name, not position perlre
  • 144. Regex: Named Captures - find matches by name, not position - avoid the dreaded$1 perlre
  • 145. Regex: Named Captures - find matches by name, not position - avoid the dreaded $1 - no longer second to Python or .Net! perlre
  • 146. Regex: Named Captures # our hypothetical format section:property = value perlre
  • 147. Regex: Named Captures $line ~~ /(w+):(w+) = (w+)/; $name = $2; $value = $3; perlre
  • 148. Regex: Named Captures $lhs_re = qr/(w+):(w+)/; $rhs_re = qr/(w+)/; $line ~~ /$lhs_re = $rhs_re/; $name = $2; $value = $3; perlre
  • 149. Regex: Named Captures $line ~~ /$lhs_re = $rhs_re/; $name = $2; $value = $3; perlre
  • 150. Regex: Named Captures $line ~~ /$lhs_re = $rhs_re/; $name = $+{ name }; $value = $+{ value }; perlre
  • 151. Regex: Named Captures $lhs_re = qr/(w+):(w+)/; $rhs_re = qr/(w+)/; perlre
  • 152. Regex: Named Captures $lhs_re = qr/(w+):(?<name>w+)/; $rhs_re = qr/(?<value>w+)/; perlre
  • 154. Regex: Backreference m{< (w+) > .+ < /1 > }x perlre
  • 155. Regex: Backreference m{< (w+) > .+ < /1 > }x perlre
  • 156. Regex: Backreference 10 perlre
  • 157. Regex: Backreference qr{(d)10} perlre
  • 159. Regex: Backreference m{< (w+) > .+ < /1 > }x perlre
  • 160. Regex: Backreference m{< (w+) > .+ < /g{1} > }x perlre
  • 161. Regex: Backreference 10 perlre
  • 162. Regex: Backreference g{10} perlre
  • 163. Regex: Backreference qr{(d)10} perlre
  • 166. Regex: Backreference qr{ (?<digit>d) g{digit} 0 }x perlre
  • 167. Regex: Exit Strategy my $wtf_re = qr{ xffn015()]*(?:[^x80-xff][^x80-xffn015()]*)*))[^x80-xf fn015()]*)*)[040t]*)*(?:(?:[^(040)<>@,;:”.[]000-037x80-x ff]+(?![^(040)<>@,;:”.[]000-037x80-xff])|”[^x80-xffn015 “]*(?:[^x80-xff][^x80-xffn015”]*)*”)[040t]*(?:([^x80- xffn015()]*(?:(?:[^x80-xff]|([^x80-xffn015()]*(?:[^x80 -xff][^x80-xffn015()]*)*))[^x80-xffn015()]*)*)[040t]* )*(?:.[040t]*(?:([^x80-xffn015()]*(?:(?:[^x80-xff]|([^ x80-xffn015()]*(?:[^x80-xff][^x80-xffn015()]*)*))[^ x80-xffn015()]*)*)[040t]*)*(?:[^(040)<>@,;:”.[]000-037x8 0-xff]+(?![^(040)<>@,;:”.[]000-037x80-xff])|”[^x80-xffn 015”]*(?:[^x80-xff][^x80-xffn015”]*)*”)[040t]*(?:([^x 80-xffn015()]*(?:(?:[^x80-xff]|([^x80-xffn015()]*(?:[^ x80-xff][^x80-xffn015()]*)*))[^x80-xffn015()]*)*)[040 t]*)*)*@[040t]*(?:([^x80-xffn015()]*(?:(?:[^x80-xff]|([ ^x80-xffn015()]*(?:[^x80-xff][^x80-xffn015()]*)*))[^ x80-xffn015()]*)*)[040t]*)*(?:[^(040)<>@,;:”.[]000-037 x80-xff]+(?![^(040)<>@,;:”.[]000-037x80-xff])|[(?:[^x80- xffn015[]]|[^x80-xff])*])[040t]*(?:([^x80-xffn015() ]*(?:(?:[^x80-xff]|([^x80-xffn015()]*(?:[^x80-xff][^ x80-xffn015()]*)*))[^x80-xffn015()]*)*)[040t]*)*(?:.[04 }; wtf
  • 168. Regex: Backreference if ($str =~ $wtf_re) { ... } perlop
  • 169. Regex: Backreference if ($str ~~ $wtf_re) { ... } perlop
  • 170. lexically scoped alternate trie-based reentrant user- defined regex pragmata
  • 173. Alternate Regex Engines - lets you change how regex work perlreapi
  • 174. Alternate Regex Engines - lets you change how regex work - but not how you use them ( , =~ s///, etc) perlreapi
  • 175. Alternate Regex Engines re::engine::POSIX
  • 176. Alternate Regex Engines egrep -r -l PATTERN DIR re::engine::POSIX
  • 177. Alternate Regex Engines my $regex = qr{ ... }; my @files = $find->file->in( $root ); say for grep { slurp ~~ $re } @files; re::engine::POSIX
  • 178. Alternate Regex Engines re::engine::POSIX
  • 179. Alternate Regex Engines egrep -r -l ‘.+?’ DIR re::engine::POSIX
  • 180. Alternate Regex Engines my $regex = qr{ ... }; my @files = $find->file->in( $root ); say for grep { slurp ~~ $re } @files; re::engine::POSIX
  • 181. Alternate Regex Engines use re::engine::POSIX; my $regex = qr{ ... }; my @files = $find->file->in( $root ); say for grep { slurp ~~ $re } @files; re::engine::POSIX
  • 182. Alternate Regex Engines use re::engine::POSIX; my $regex = qr{ ... }x; my @files = $find->file->in( $root ); say for grep { slurp ~~ $re } @files; re::engine::POSIX