Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re^3: Can we make hash key check in 'if' condition case insensitive?

by syphilis (Archbishop)
on Feb 09, 2018 at 01:02 UTC ( [id://1208769]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Can we make hash key check in 'if' condition case insensitive?
in thread [SOLVED: Can we make hash key check in 'if' condition case insensitive?

fc should be used for case-insensitive comparisons, not lc

Do you have a usage example for "fc" that actually works ?

I certainly don't. On Win32 perls 5.24.0, 5.26.0, 5.27.8 and Ubuntu perl 5.26.0 (all of which provide documentation for the fc function), I tried the following script:
use strict; use warnings; my $this = 'hello'; my $that = 'tata'; if(fc($this) eq fc($that)) {print "wtf\n"}
In every case it simply output:
Undefined subroutine &main::fc called at try.pl line 7.


Update Aah .. you have to use feature 'fc'; to enable it.
(Clearly stated at the very end of the documentation.)
I personally would not recommend anything that requires feature to be enabled.

Cheers,
Rob

Replies are listed 'Best First'.
Re^4: Can we make hash key check in 'if' condition case insensitive?
by ikegami (Patriarch) on Feb 09, 2018 at 05:29 UTC

    I personally would not recommend anything that requires feature to be enabled.

    *shrug* You're free to use another implementation if you don't want to use perl's. Unicode::UCD might provide something.

      You're free to use another implementation if you don't want to use perl's

      I wasn't trying to imply that I have a better recommendation - I don't.
      Personally, I will just use lc(), as it is quite adequate for the situations in which I use it.
      However, just as there are situations in which lc() does not do the right thing, there are also portability issues with fc() - and I think it would have been better if you had mentioned those portability issues when you said that "fc should be used for case-insensitive comparisons, not lc".

      I suspect that *you* are so well aware of that portability issue, that it didn't even occur to you to mention it.
      But dumb pricks like me are not so quick on the uptake, especially when the crucial information is held back until the very end of the documentation (not your fault).

      This is one of the interesting aspects of the way that Larry Wall has "stitched up" perl5.
      In a normal situation, if there were a number of features that we wished to add to perl, the porters would just release a new version of perl named "perl-6.0.0" - a version of perl that provided those new features whilst promising no compatibility (yet providing extensive compatibility) with perl-5.x.x.
      But Larry has successfully (and with deliberate intention) ensured that can't happen.
      Therefore, in accordance with the backward-compatibility of perl-5.x.x, the only way that new features can be added is via 'use feature'.
      I expect that, by about perl-5.36.0, the recommendation will no longer be that you start your perl script with:
      use strict; use warnings;
      Rather, it will be that you begin your scripts with:
      use strict; use warnings; use feature ':5.26.0';
      And, with 5.46.0, you begin your scripts with:
      use strict; use warnings; use feature ':5.36.0';
      ... or something along those lines.

      The disappointing thing about that is that there's a large number of monks here (1nickt ++ is a notable exception) who think that's completely acceptable.

      Cheers,
      Rob

Log In?
Username:
Password:

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

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

    No recent polls found