CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Question on inline redirection

 



jujiro_eb
New User

Mar 17, 2009, 11:30 AM

Post #1 of 8 (1635 views)
Question on inline redirection Can't Post

Folks,

I am relatively new to Perl but very comfortable with Korn Shell scripting. Can someone please help me with the following code:

system ("sqlplus.exe -s uid/pwd@myserver "); <<EOT
select * from emp;
exit
EOT


Or using __DATA__ marker. I am sure you get the idea that I want to pass a bunch of SQL statments to sqlplus and capture the stdout (Which I know how to do).

I do not want to resort to storing sql statements in a separate file and using something like this:

system ("sqlplus.exe -s uid/pwd@myserver @myscript.sql");

Any help will be highly appreciated.

Ash


FishMonger
Veteran / Moderator

Mar 17, 2009, 12:42 PM

Post #2 of 8 (1630 views)
Re: [jujiro_eb] Question on inline redirection [In reply to] Can't Post

Why not use the standard Perl DBI module.

DBI- Database independent interface for Perl
http://search.cpan.org/~timb/DBI-1.607/DBI.pm

DBD::Oracle - Oracle database driver for the DBI module
http://search.cpan.org/~pythian/DBD-Oracle-1.22/Oracle.pm


jujiro_eb
New User

Mar 17, 2009, 12:49 PM

Post #3 of 8 (1628 views)
Re: [FishMonger] Question on inline redirection [In reply to] Can't Post

Hello FishMonger,

This script is just a port of KSH script for Windows platform. My boss does not want to re-write anything if he does not have to.

Regards.

Ash


FishMonger
Veteran / Moderator

Mar 17, 2009, 1:02 PM

Post #4 of 8 (1627 views)
Re: [jujiro_eb] Question on inline redirection [In reply to] Can't Post

To capture the output of the sqlplus command, you need to use backticks or the qx() operator, not system().

I have not worked with sqlplus.

How do you pass it the sql statements when executing it from the command line?

Where and how are you storing these statements, directly in the script or in an external file?


FishMonger
Veteran / Moderator

Mar 17, 2009, 1:09 PM

Post #5 of 8 (1626 views)
Re: [jujiro_eb] Question on inline redirection [In reply to] Can't Post


In Reply To
Hello FishMonger,

This script is just a port of KSH script for Windows platform. My boss does not want to re-write anything if he does not have to.

Regards.

Ash


Does that mean that you're running the KSH script in a simulated nix environment such as cygwin? Or, are you writing a Perl script to replace the KSH script. If the latter, then rewriting the script from the ground up is the best approach. In 99.99% of the time, a straight syntax conversion is the wrong, if not worst, approach.


jujiro_eb
New User

Mar 17, 2009, 1:34 PM

Post #6 of 8 (1623 views)
Re: [FishMonger] Question on inline redirection [In reply to] Can't Post

Hello FishMonger,

Thanks for taking the interest in my question.

Let me try to answer to both of your posts.

1. No I am not simulating KSH from Pearl. The original script was written on Unix system as a Korm shell script. I am converting the script to run on Windows platform using Perl.

2. There are several ways to run commands in sqlplus.

Interactive way:

sqlplus userid/pwd@connectionstring

It gives you sql prompt and you can fire up queries from stdin (your keyboard).

While running in batch mode you can put all our queries in a file (Let us call it myqueries.sql) and launch sql plus as following:

sqlplus uid/pwd@connectionstring @myqueries.sql

This syntax is universal no matter what the platform is.

I want to avoid making myqueries.sql as a separate file. I want to store all the queries in the Pearl script and somehow feed them to sqlplus through redirection. I searched a lot of articles where folks claimed that they have achieved what I am looking (See sample below), however I am getting "<< was unexpected at this time" error.

This claims to be working:


Code
  

$str = "sqlplus -s <<EOF \n" .
"$db_login \n" .
"WHENEVER SQLERROR EXIT FAILURE; \n" .
"EXEC @ARGV[0]; \n".
"exit; \n".
"EOF\n";

$return_code = system($str);



jujiro_eb
New User

Mar 17, 2009, 3:22 PM

Post #7 of 8 (1616 views)
Re: [jujiro_eb] Question on inline redirection [In reply to] Can't Post

Folks,

I have the answer to my question from perlmonks.org. I think it is an excellent post (At least for me) to learn about piping input from perl script to a program. Take a look:

http://www.perlmonks.org/?node_id=751259

Regards.

Ash


FishMonger
Veteran / Moderator

Mar 17, 2009, 5:16 PM

Post #8 of 8 (1613 views)
Re: [jujiro_eb] Question on inline redirection [In reply to] Can't Post

There are at the very least 3 different methods you can use. Here's a link that gives a brief example of several of them.

http://yong321.freeshell.org/computer/OracleAndPerl.html

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives