Hi Jim,

Thanks for your advise ...

Am currently having issues with using DBI and DBD and is constrained on
installing new DBI versions so at the moment my only option is to shell out.

If I can get a "fix" on using DBI/DBD where I do not need to supply username
and password, then I will check choose to use that as the final choice.

BTW, am a bit confused on when to use and not use DBD, can you please
elaborate on that if you don't mind? use DBI seems to be sufficient, is DBD
when the functionality that you want to use is specific to the database?

Thanks in advance.

On Thu, Feb 11, 2010 at 2:11 PM, Jim Gibson <jimsgib...@gmail.com> wrote:

> On 2/10/10 Wed  Feb 10, 2010  3:07 PM, "newbie01 perl"
> <newbie01.p...@gmail.com> scribbled:
>
> > Hi all,
> >
> > We are in the process of changing UNIX and MS-DOS scripts into Perl,
> mostly
> > UNIX scripts and there are a lot of codes that uses the <<EOF and EOF
> pair.
> > Am just wanting to know if there are better alternative to what I've been
> > doing so far.
> >
> > Example of these are as below:
> >
> > Example 01:
> >
> > UNIX script version:
> > num_records=`sqlplus -S "/as sysdba" << EOF | sed 's# *##g'
> >    set heading off
> >    set feedback off
> >    set pages 0
> >    set echo off
> >    set trimspool on
> >    select count(1) from all_tables where owner = '${owner}';
> >    exit
> > EOF`
> >
> > Changed to Perl - this work alright, is there a better way of doing this?
> >
> > $owner = 'SYSMAN';
> > $num_records=`sqlplus -S "/as sysdba" << EOF | sed 's# *##g'
> >    set heading off
> >    set feedback off
> >    set pages 0
> >    set echo off
> >    set trimspool on
> >    select count(1) from all_tables where owner = '${owner}';
> >    exit
> > EOF`;
> > print $num_records;
> >
> > exit 0;
>
> Rather than shelling out and creating an external process to run sqlplus,
> you should consider using a Perl database module to allow your program to
> connect to the database directly. Checkout the DBI module and a DBD module
> for your particular database. This will require a significant rewriting
> effort, however.
>
> >
> >
> > Example 02:
> >
> > UNIX script version:
> > sqlplus -S "/as sysdba" << EOF
> ...
> > EOF
> >
> > Changed to Perl - this work alright, is there a better way of doing this?
> >
> > `sqlplus -S "/as sysdba" << EOF
>
> Use the system function if you do not want to capture the output of the
> sqlplus program.
>
>
> >
> > Example 03:
> >
> > UNIX script version:
> >
> > cat /dev/null > eol_unix.out
> > cat >> eol_unix.out << EOF
> > `( ls ;
> > echo ;
> > echo "+----------------------------------------------+" ;
> > echo ;
> > df ;
> > echo ;
> > echo "+----------------------------------------------+" ;
> > echo ;
> > uname -a )`
> > EOF
> >
> > Changed to Perl - this work alright, is there a better way of doing this?
> >
> > open(OUTPUT, " > eol_unix.out") or die $!;
>
> Better to use the three-parameter version of open and lexical file handle
> variables:
>
> open( my $output, '>', 'eol_unix.out' ) or die("Can't open eol_unix.out:
> $!");
>
> > print OUTPUT <<`EOL`;
>
> print $output ...
>
> > ls
> > echo
> > echo "+----------------------------------------------+"
> > echo
> > df
> > echo
> > echo "+----------------------------------------------+"
> > echo
> > uname -a
> > EOL
> >
> >
> > Any feedback will be very much appreciated. Thanks in advance
>
>
>

Reply via email to