tphyahoo has asked for the wisdom of the Perl Monks concerning the following question:

Monks, I am on a german WinXP box. I want to ping jenda's perl repository and display an error message if his repository is down, otherwise add it to my active repositories.

Problem is, =~ won't match the special 'ü' character coming in from dos. How do I get perl to behave for me in this scenario?

Thanks very much for your help.

my $result = `ping -n 1 "jenda.krynicy.cz" ` . "\n"; print "result: $result\n\n"; #if ($result =~ /zeitüberschreitung/i) { if ($result =~ /zeitüberschreitung/i) { # should match but fails becau +se of german characters #ping timed out, something is wrong with the repository print "Ping timed out for $domain: \n\n $result \n\n"; } else { #good repository. print "$domain passed ping: \n"; print `ppm repository add $repository $location` . "\n\n"; }

Replies are listed 'Best First'.
Re: matching german characters output from system call.
by bart (Canon) on May 09, 2005 at 18:12 UTC
    Use a wildcard for that character.
    if ($result =~ /zeit.berschreitung/i) {
Re: matching german characters output from system call.
by thundergnat (Deacon) on May 09, 2005 at 18:24 UTC

    You need to change the encoding from DOS cp437 (assuming English codepage) to Latin-1 or utf-8.

    use Encode; my $result = `ping -n 1 "jenda.krynicy.cz" ` . "\n"; print "result: $result\n\n"; my $latinresult = $result; Encode::from_to($latinresult, 'cp437', 'iso-8859-1'); if ($latinresult =~ /zeitüberschreitung/i) { #ping timed out, something is wrong with the repository print "Ping timed out for $domain: \n\n $result \n\n"; } else { #good repository. print "$domain passed ping: \n"; print `ppm repository add $repository $location` . "\n\n"; }

    Note: this only addresses the encoding problem, there are several other potential problems with the script

Re: matching german characters output from system call.
by Animator (Hermit) on May 09, 2005 at 18:18 UTC

    I don't think it is a local thingie...

    I believe it to be a problem with the represntation of that character, as in, in a dos-prompt it is displayed differently then in windows.

    Here is something you can try: edit a file in dos, type the charachter, and open that file in windows (after saving it ofc)...

    Or another possibility, run: perl -wle "printf qq(%02X\n), ord(qq(ü));"

    This code should return a hex-charachter, which you can use in your code like: \xFC (that code returns FC on my system, but it might be different on yours...)

    Update: doing what I suggested, (creating the file in DOS and opening it in windows), returns the value 81... so try with \xFC or \x81.

    Another thing you might want to do is use Net::Ping instead of the ping command... (not sure if it works though since I haven't used it before)

Re: matching german characters output from system call.
by sh1tn (Priest) on May 09, 2005 at 17:53 UTC
    ... if( $result =~ /\Qzeitüberschreitung\E/i ){ ...


      Nope, that didn't work. I'm pretty certain it's a locale thing, but I still haven't really wrapped my head around this locale concept... :-
Re: matching german characters output from system call.
by tphyahoo (Vicar) on May 10, 2005 at 10:38 UTC
    When I converted the script "Ansi->OEM" using the editpad text editor, then saved and reran, it worked.

    I had resolved a similar problem at The problem was utf-8 versus windows ansi using this technique several months ago, and unfortunately clean forgotten about it. (Long stressy day yesterday.)

    However, although this worked, I think it would be better/more permanent/more portable to be using perl's encoding powers, and I really appreciate all the answers and will be studying them carefully.