Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re^3: Perl version dependent code (updated)

by hippo (Bishop)
on Feb 04, 2019 at 09:29 UTC ( [id://1229337]=note: print w/replies, xml ) Need Help??


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

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)

Replies are listed 'Best First'.
Re^4: Perl version dependent code (updated)
by Aldebaran (Curate) on Feb 05, 2019 at 09:05 UTC

    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://1229337]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-18 21:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found