How can I make case-sensitive regular expressions match for Russian letters?

I have a list of directory paths and you need to filter out some of them. My match pattern is in an encoding other than Unicode.

I tried the following:

require 5.004;
use POSIX qw(locale_h);
my $old_locale = setlocale(LC_ALL);
setlocale(LC_ALL, "ru_RU.cp1251");

@{$data -> {doc_folder_rights}} = 
       grep {
              # catalog path pattern in $_REQUEST{q}
              $_->{doc_folder} =~/$_REQUEST{q}/i; 
            } 
            @{$data -> {doc_folder_rights}};

setlocale(LC_ALL, $old_locale);

I need a case-insensitive regular expression if the pattern contains Russian letters.

+3
source share
1 answer

There are several (potential) problems in the code:

  • Your code filters out all doc_folders that do not match the regular expression in $_REQUEST{q}, however the question suggests that you want to do the opposite.

  • . ( setlocale) perl , . , $_REQUEST{q} .

, Perl- Unicode- , . Perl I/O, . stdin, ARGV Perl , .

, :

  • , Perl, . .
  • , $_REQUEST , Perl binmode($fh, ":encoding(cp1251)");. $_REQUEST.
  • $string = Encode::decode(Encoding, $octets), Perl $octets $octets , Unicode, Encoding. , $octets, .
  • $_REQUEST , , cgi- , , , cgi-, .
+2

Source: https://habr.com/ru/post/1739110/


All Articles