in reply to EOF problem with sqlplus on Windows

qx quotes its argument (similar to a double-quoted string, only that the string is executed afterwards. Hence the here document is not interpreted by Perl.

Maybe you intended to have the HERE document being interpreted by the shell, but this doesn't work either, because passing a multi-line string to qx does not cause the shell to execute a multi-line script. Here a simple example from the command line (I'm using Windows for this, but the same applies to Linux etc):

C:\>perl -lwe "my $x=qx(echo a\necho b); print $x" a echo b
As you can see, the shell is not executing two echo commands, but only one.

If you want to execute multi-line shell commands, I suggest you create a temporary file (File::Temp), write the shell script into it, and execute it.
-- 
Ronald Fischer <ynnor@mm.st>

Replies are listed 'Best First'.
Re^2: EOF problem with sqlplus on Windows
by choroba (Cardinal) on Mar 22, 2012 at 11:28 UTC
    No. On Linux, I get
    a b
    as output.
    Even this works:
    perl -lwe 'my $x=qx(echo a echo b);print $x'
    i.e. using the newline itself.

    Nevertheless, HERE docs are not interpreted by the shell.
    Update: Stupid me. Used echo instead of cat in testing.

Re^2: EOF problem with sqlplus on Windows
by JavaFan (Canon) on Mar 22, 2012 at 11:31 UTC
    Maybe you intended to have the HERE document being interpreted by the shell, but this doesn't work either, because passing a multi-line string to qx does not cause the shell to execute a multi-line script.
    Couldn't bother to try?
    $ export PS2=""; perl -E '$x = `cat <<FOO hello world FOO`; print uc $x' HELLO WORLD $
    qx doesn't filter out newlines, and the shell is smart enough to know how to deal with newlines.
      Couldn't bother to try?
      At that time, I only had access to a Windoze system, where I tried it of course (as you can see from my posting). Thanks for demonstrating that this is different on *nix.

      -- 
      Ronald Fischer <ynnor@mm.st>
      JavaFan, It still does not work. But we tried with a colleague to execute sqlplus with the "<<" on the server itself. The same error occurs : "<< etait inattendu" ( << was unexpected ) We need to search the way to execute multiple sqlplus commands at the windows prompt now. Thanks Jean-michel
        I never claimed it would work. In fact, it seems you have a Windows shell problem. I've never worked on Windows, don't care about the platform, and never will work on Windows. I don't have any suggestions how to solve your problem (well, except upgrading to something useful, like VMS or a Unix flavour or even Linux)

        What I did point out was that the "problem" isn't caused by qx not able to deal with newlines. It can. If the shell you're using cannot deal with multi-line statements, get a better shell. If your shell does not understand here documents, don't send a here document to it. This is not a Perl problem.

        What shell does your server run?
        YES !!! ( thanks to http://damir-vadas.blogspot.fr/2010/11/how-to-redirect-sqlplus-result-in.html ) We thus made it this way :
        $my_sql="select sysdate from dual"; my $request="echo $my_sql\|sqlplus system/password"; $result=qx($request);
        Thanks for your help Jean-michel