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

Monks, I am writing a perl script that runs an executable file, then parses through the results, however im having some issues, for some reason, when the .exe is ran, it returns this:
S t a r t i n g c h e c k , p o r t : 8 0 , w e b : " / " . C r e a t e d : 0 7 A p r 2 0 1 0 1 8 : 2 2 : 5 7 - 0 0 0 0 V e r s i o n : 5 . 0 . 2 . 6 7 9 0 P o r t 8 0 : C h e c k c o m p l e t e d .
So it puts a space after every character it seems, so single spaces are double spaces. I googled it quite a bit, but I couldnt find a way to remove all single spaces, and make double spaces into a single space without totally removing it, any ideas?

Replies are listed 'Best First'.
Re: Perl Regex with Extra Spaces
by ikegami (Patriarch) on Apr 07, 2010 at 22:53 UTC

    Your executable appears to output UTF-16le. Decode it. A convenient way for files:

    # With LF<->CRLF conversion open(my $fh, '<:raw:perlio:encoding(UTF-16le):crlf', $fn)

    or

    # Without LF<->CRLF conversion open(my $fh, '<:raw:perlio:encoding(UTF-16le)', $fn)
Re: Perl Regex with Extra Spaces
by BrowserUk (Patriarch) on Apr 07, 2010 at 22:10 UTC
    print $s;; S t a r t i n g c h e c k , p o r t : 8 0 , w e b : " / " . C r e a t e d : 0 7 A p r 2 0 1 0 1 8 : 2 2 : 5 7 - 0 0 0 0 V e r s i o n : 5 . 0 . 2 . 6 7 9 0 P o r t 8 0 : C h e c k c o m p l e t e d $s =~ s[(.) ][$1]g;; print $s;; Starting check, port: 80, web: "/". Created: 07 Apr 2010 18:22:57 -0000 Version: 5.0.2.6790 Port 80: Check completed

    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.
      Oh wow, that was fast, nice job! Why do you use ;; instead of ;?

        Just an artifact of my REPL environment. Nothing to worry about.


        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.
Re: Perl Regex with Extra Spaces
by Jasper (Chaplain) on Apr 09, 2010 at 15:43 UTC
    What you want is y/ //s
      What is that exactly?
        Its the transliteration operator tr/// (same as y///), not to be confused with s///.

        Your problem is that you're not decoding UTF-16le.

Re: Perl Regex with Extra Spaces
by jhyland87 (Sexton) on Apr 08, 2010 at 18:45 UTC
    The problem seems to have changed a bit. My goal is to execute a command, (OWSADM.EXE -o fulluninstall -p 80 -m 123.123.123.123), on a remote server, and get the results, and parse through it to see if it was successful. Currently, im executing it via psexec, and getting that output, but psexec seems to throw my script off, as it has all of its annoying headers and what not. Anyone have any good ideas on executing commands like that though something other than telnet or psexec? I just want to run it and get the result
      Anyone have any good ideas on executing commands like that though something other than telnet or psexec?

      SSH perhaps?

      If you meant something else, I don't see how you can avoid using a Client<->Server system in order to remotely execute a command...


      but psexec seems to throw my script off, as it has all of its annoying headers and what not

      (Assuming your script is running on a windows machine, and that you have decoded the UTF16 output as others above have advised) If you parse the remote command's output line by line and look for the string \r\s you should be able to safely ignore that line and assume it is one of those pesky headers that psexec creates...

      1. It won't remove the Copyright stuff, though that should be easy to skip/ignore...
      2. It shouldn't remove any real warnings or errors generated by your remote command (OWSADM.exe). But, test it for yourself, don't rely on my word for it...