6. 2. Fold case
• Compare strings non-unicode
uc($string1) eq = uc($string2)
$string1 = ‘A’; $string2 = ‘a’;
uc(‘A’) = A uc(‘a) =A
Result: OK
$string1 = ‘ß’;
uc(‘ß’) = ‘SS’
It’s NOT OK
7. 2. Fold case
• Compare strings in unicode
use feature ‘fc’;
fc($unicode1) eq fc($unicode2)
• Use casefolding
• inside a double-quoting string - "F$variable"
8. 2. quotameta
• In Perl 5.16 adopted a Unicode-defined strategy for quoting
non-ASCII characters
my $string = ‘Perl May 2011 in Moscow';
my $substr = ‘May.*?Moscow';
$string =~ s{Q$substrE}{Mova 2012 in Kiev};
• Or:
use feature ‘unicode_strings’;
my $string = ‘Perl May 2011 in Moscow';
my $substr = ‘May.*?Moscow';
my $quoted_substr = quotemeta($substr);
$string =~ s{$quoted_substr}{Mova 2012 in Kiev};
9. 2. unicode_eval, evalbytes
unicode_eval default feature of Perl 5.16
eval – evaluate string of characters
evalbytes – die if the string contains any
characters outside the 8-bit range
10. 3. Other features
• current sub __SUB__
• CORE namespace
• array base
• debugger
11. 3. Current sub
• current_sub (__SUB__) - reference to the current
subroutine or undef outside of subroutine
• easier to write recursive closures.
use feature ‘current_sub’;
sub closure {
my $init = shift;
return sub {
state $counter = $init;
return if $counter++ > 10;
__SUB__->();
}
}
12. 3. CORE Namespace
• Namespace for Perl’s core routines
• Give access to the original built-in of Perl
use v5.16;
or
use feature ‘say’;
or
CORE::say “yes”;
13. 3. array base
• special variable for array base
• The 'array_base' feature replace variable $[
• $[ affected also string not only arrays
use feature ‘array_base’;
$[ = 1;
14. 3. debugger
• Tracing mode (t command) accept number of
subroutine for trace
• Breakpoints with file names
$ b [file]:[line] [condition]
$ b lib/MyModule.pm:237 $x > 30