First, you should know that double quotes interpolate, and Perl will try to interpolate an array named @myserver with code that says "sqlplus.exe -s uid/pwd@myserver". To avoid the interpolation, you can either put a backslash in front of the at sign to escape it, or use single quotes which don't interpolate ('sqlplus.exe -s uid/pwd@myserver' or "sqlplus.exe -s uid/pwd\@myserver"). If you Use strict and warnings, that will catch a mistake like that and lots of others.

Second, it looks as if you're trying to pipe data to this program. In Perl, you'd do that with open like so:

open my $pipe_fh, '|-', 'sqlplus.exe -s uid/pwd@myserver' or die "Can't open pipe: $!";

Then you can print a heredoc into the pipe:

print {$pipe_fh} <<'END_OF_SQL' select * from emp; exit; END_OF_SQL ;

Note that I put single quotes around the heredoc terminator to make it not interpolate. The default is interpolation, which you also get if you put the terminator in double quotes.

If you're using __DATA__, that could look like this:

print {$pipe_fh} <DATA>;

When you close the pipe, Perl will wait for the program to finish, and you get its exit status in $?.

close $pipe_fh or die "close failed: $!"; if ( $? ) { die "sqlplus returned non-zero exit status '$?'"; }

If you use English, you can refer to $? as $CHILD_ERROR instead, which is a bit more readable.

Update: Here's all the code I suggested together in one block:

use strict; use warnings; use English '-no_match_vars'; open my $pipe_fh, '|-', 'sqlplus.exe -s uid/pwd@myserver' or die "Can't open pipe: $!"; print {$pipe_fh} <DATA>; close $pipe_fh or die "close failed: $!"; if ( $CHILD_ERROR ) { die "sqlplus returned non-zero exit status '$CHILD_ERROR'"; } __DATA__ select * from emp; exit;

Note that I haven't tested this, but I think it should run.


In reply to Re: Question on inline redirection by kyle
in thread Question on inline redirection by jujiro_eb

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.