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?
Just wanted to try this option out as well. So, I tried to use fc in the same example that choroba suggested and make it work. But it displays only "John" as a castaway.
#!/localperl/bin/perl use warnings; use strict; use feature 'fc'; my @castaways = qw( john Jane LUKE ); my @list_1 = qw( not John JANE luke ); my %hash = map { $_, 1 } @castaways; for my $person (@list_1) { if ( $hash{ fc($person) }) { # Tried with exists as well. Same res +ult. print "$person is a castaway\n"; } }
Result: John is a castaway
So I think in my case, using lc is the only option. BTW I am using (v5.24.0)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Can we make hash key check in 'if' condition case insensitive?
by pryrt (Abbot) on Feb 09, 2018 at 17:26 UTC | |
by Perl300 (Friar) on Feb 09, 2018 at 19:15 UTC | |
|
Re^4: Can we make hash key check in 'if' condition case insensitive?
by poj (Abbot) on Feb 09, 2018 at 17:23 UTC |