Hello, fellow seekers of enlightenment,

I'm trying to construct a simple regex that checks if a variable contains characters valid in a unix path. The regex works as it should when there are no umlauts in the string, but when testing different inputs, I noticed it refuses to match any umlauts. What bugs me, is that it does match the exact same string when I use a variable, but not when handed down by $ENV{'PATH_TRANSLATED'} - which probably is a non-encoded 8bit string. A shortened example:

$testString = "/usr/home/december/public_html/experiments/html/files/b +lëh.txt"; $fileAsked = $ENV{'PATH_TRANSLATED'}; print "Trying with: $testString\n"; print "Trying with: $fileAsked\n"; print "VALID1\n" if ($testString =~ /^([\w\s\/.]+)$/); print "VALID2\n" if ($fileAsked =~ /^([\w\s\/.]+)$/); print "SUCCEEDED1\n" if (utf8::upgrade($testString)); print "SUCCEEDED2\n" if (utf8::upgrade($fileAsked)); print "VALID3\n" if ($testString =~ /^([\w\s\/.]+)$/); print "VALID4\n" if ($fileAsked =~ /^([\w\s\/.]+)$/);

prints:

Trying with: /usr/home/december/public_html/experiments/html/files/blë +h.txt Trying with: /usr/home/december/public_html/experiments/html/files/blë +h.txt SUCCEEDED1 SUCCEEDED2 VALID3

Note that both strings and regex's are exactly the same, but after conversion, one matches, and the other doesn't. I suspect some utf8 problems, or a wrong charset used for \w. Perl version is 5.8.3.

How do I make the \w match umlauts consistently? Do I need to set a locale even for utf8? This behavior doesn't seem logical to me.


In reply to problems matching umlauts in env vars by december

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.