Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Perl version dependent code (updated)

by Aldebaran (Curate)
on Feb 03, 2019 at 22:13 UTC ( [id://1229322]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl version dependent code (updated)
in thread Perl version dependent code

I've been mulling this over for a bit and expected this to show equality:

$ ./1.version.pl a is 5.026001 b is v5.26.1 version is v5 version is v5.26.1 c is ж d is Ж did not match $ cat 1.version.pl #!/usr/bin/perl -w use 5.011; use Path::Tiny; use POSIX qw(strftime); use if $] ge '5.016', feature => 'fc'; use if $] lt '5.016', 'Unicode::CaseFold' => 'fc'; my $a = $]; say "a is $a"; my $b = $^V; say "b is $b"; printf "version is v%d\n", $a; # Perl's version printf "version is v%vd\n", $b; # Perl's version my $c = "ж"; say "c is $c"; my $d = "Ж"; say "d is $d"; if (fc($c) eq fc($d)){ say "expressions matched"; } else { say "did not match"; } __END__ $

The characters are ж and Ж .

Replies are listed 'Best First'.
Re^3: Perl version dependent code (updated)
by hippo (Bishop) on Feb 04, 2019 at 09:29 UTC
    my $c = "ж";

    That's an HTML entity and consists of 7 separate characters. If you typed it like this then hopefully it becomes obvious why it doesn't match against "Ж" which is an entirely different string, folding notwithstanding.

    OTOH, if you didn't type it like this but instead used a unicode literal string such as

    my $c = "ж";
    then your code is missing the absolutely necessary use utf8; pragma in order to decode this character properly.

    (Edited for typo)

      Indeed...

      $ ./1.version.pl 
      a is 5.026001
      b is v5.26.1
      version is v5
      version is v5.26.1
      c is ж
      d is Ж
      expressions matched
      $ cat 1.version.pl 
      #!/usr/bin/perl -w
      use 5.011;
      use Path::Tiny;
      use POSIX qw(strftime);
      use if $] ge '5.016', feature => 'fc';
      use if $] lt '5.016', 'Unicode::CaseFold' => 'fc';
      use utf8;
      use open OUT => ':encoding(UTF-8)', ':std';
      
      my $a = $];
      say "a is $a";
      
      my $b = $^V;
      say "b is $b";
      
      printf "version is v%d\n", $a;  # Perl's version
      printf "version is v%vd\n", $b;  # Perl's version
      
      my $c = "ж";
      say "c is $c";
      
      my $d = "Ж";
      say "d is $d";
      
      if (fc($c) eq fc($d)){
      say "expressions matched";
      
      } else {
          say "did not match";
      }
      __END__ 
      $ 
      
      

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1229322]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 15:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found