Friday, 15 June 2012

perl - How to use regex in not ASCII strings? -



perl - How to use regex in not ASCII strings? -

i have code:

opendir(dir, "."); while (readdir dir) { print $1, "\n" if $_ =~ /(\w+)/i; }

it gets ascii strings of course. how can non ascii strings in output using regexp?

upd

for illustration if in "." directory there 2 files file , другойфайл. when run script file in output i'd file non english language name другойфайл

the next code seems work:

use warnings; utilize strict; utilize encode qw(decode); $dir = $argv[0] || '.'; opendir $dh, $dir or die "$0: $dir: $!\n"; while (readdir $dh) { $_ = decode 'utf-8', $_; print $1, "\n" if /(\w+)/; }

this assumes file scheme stores names in utf-8, of course.

output:

file другойфайл

regex perl unicode

No comments:

Post a Comment