Help on Perl Scripting

Hi,

Im trying to convert c shell script to PERL but haven't use PERL
before can anybody help me on this? Thanks in advance.


#! /bin/csh

if ($#argv <= 2) then
echo "Usage : $0 <table_name> <config_file> <config_file_2>"
exit
endif

set table = $argv[1]
set config_file = $argv[2]
set config_file_2 = $argv[3]

source $config_file

if ( $#argv >= 3 ) then
if (-f $config_file_2) then
source $config_file_2
endif
endif

if !(-d $backup) then
echo ""
echo "Create backup directory..."
mkdir $backup
endif

if !(-d $backup/$DB) then
echo ""
echo "Create backup directory for database..."$DB
mkdir $backup/$DB
endif

bcp $DB..$table out $backup/$DB/$table -c -U$UID -P$PSW -S$SVR

echo " Rename table..."
sed -e s/table/$table/g modify_rename_table.sql | runsql

#! /bin/csh

if ($#argv <= 2) then
echo "Usage : $0 <table_name> <config_file> <config_file_2>"
exit
endif

set table = $argv[1]
set config_file = $argv[2]
set config_file_2 = $argv[3]

source $config_file

if ( $#argv >= 3 ) then
if (-f $config_file_2) then
source $config_file_2
endif
endif

if !(-d $backup) then
echo ""
echo "Create backup directory..."
mkdir $backup
endif

if !(-d $backup/$DB) then
echo ""
echo "Create backup directory for database..."$DB
mkdir $backup/$DB
endif

bcp $DB..$table out $backup/$DB/$table -c -U$UID -P$PSW -S$SVR

echo " Rename table..."
sed -e s/table/$table/g modify_rename_table.sql | runsql

if (-f $table.convert.sql) then
echo " Converting temp table..."
runsql < $table.convert.sql
endif

echo " Recreate table..."
if (-f $newtabdir/$table.tab.sql) then
runsql < $newtabdir/$table.tab.sql
else
if (-f $alt1tabdir/$table.tab.sql) then
runsql < $alt1tabdir/$table.tab.sql
else
if (-f $alt2tabdir/$table.tab.sql) then
runsql < $alt2tabdir/$table.tab.sql
else
if (-f $alt3tabdir/$table.tab.sql) then
runsql < $alt3tabdir/$table.tab.sql
else
if (-f $alt4tabdir/$table.tab.sql) then
runsql < $alt4tabdir/$table.tab.sql
else
if (-f $alt5tabdir/$table.tab.sql) then
runsql < $alt5tabdir/
$table.tab.sql
endif
endif
endif
endif
endif
endif

echo " Copy data..."
if (-f $table.copy.sql) then
runsql < $table.copy.sql
else
if (-f $table.select.sql) then
sed -e s/table/$table/g modify_copy_data.sql | sed -e s/\*/`cat
$table.select.sql`/g | runsql
else
sed -e s/table/$table/g modify_copy_data.sql | runsql
endif
endif

echo " Drop temp table..."
runsql < modify_drop_temp.sql

source ../PROMOTE.uncfg

Regards,
Laarni
Laarni [ Do, 10 Januar 2008 10:06 ] [ ID #1904885 ]

Re: Help on Perl Scripting

Laarni wrote:
> Im trying to convert c shell script to PERL but haven't use PERL
> before can anybody help me on this?

Sure. http://learn.perl.org/

> Thanks in advance.

You're welcome.

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl
Gunnar Hjalmarsson [ Do, 10 Januar 2008 10:35 ] [ ID #1904886 ]

Re: Help on Perl Scripting

In article
<75c28a2e-7b3f-4d1b-907d-c75488098c89 [at] d21g2000prf.googlegroups.com>,
Laarni <Laarni.Zosa [at] ubs.com> wrote:

> Hi,
>
> Im trying to convert c shell script to PERL but haven't use PERL
> before can anybody help me on this? Thanks in advance.

Here is some code to get you started. It is all untested and guaranteed
to have mistakes:

>
>
> #! /bin/csh

#!/usr/bin/perl
use strict;
use warnings;

>
> if ($#argv <= 2) then
> echo "Usage : $0 <table_name> <config_file> <config_file_2>"
> exit
> endif

if( [at] ARGV <= 2 ) {
print "Usage: $0 <table_name> <config_file> <config_file_2>\n";
exit;
}

>
> set table = $argv[1]
> set config_file = $argv[2]
> set config_file_2 = $argv[3]

my( $table, $config_file, $config_file_2 ) = [at] ARGV;

>
> source $config_file

do $config_file or die("Can't do $config_file: $!");

>
> if ( $#argv >= 3 ) then
> if (-f $config_file_2) then
> source $config_file_2
> endif
> endif

if( $config_file_2 ) {
if( -f $config_file_2 ) {
do $config_file_2 or die("Can't do $config_file_2: $!");
}
}

>
> if !(-d $backup) then
> echo ""
> echo "Create backup directory..."
> mkdir $backup
> endif

if( ! -d $backup ) {
mkdir $backup or die("Can't create $backup directory: $!");
}

>
> if !(-d $backup/$DB) then
> echo ""
> echo "Create backup directory for database..."$DB
> mkdir $backup/$DB
> endif

(similar)

>
> bcp $DB..$table out $backup/$DB/$table -c -U$UID -P$PSW -S$SVR

(Where do $UID, $PSW, and $SVR come from? $UID looks like user id and
Perl has built-in $< for that. If $PSW and $SVR are environment
variables, you can get them from the %ENV hash as $ENV{PSW} and
$ENV{SVR}.)

system(" bcp $DB..$table out $backup/$DB/$table -c -U$< -P$ENV{PSW}
-S$ENV{SVR");

>
> echo " Rename table..."
> sed -e s/table/$table/g modify_rename_table.sql | runsql

(read modify_rename_table.sql file, modify, and call system to run
runsql perhaps)


>
> #! /bin/csh

(Are you starting over?)

[rest snipped]

Good luck!

--
Jim Gibson

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com
Jim Gibson [ Do, 10 Januar 2008 19:28 ] [ ID #1904903 ]
Perl » comp.lang.perl.misc » Help on Perl Scripting

Vorheriges Thema: FAQ 7.21 How do I redefine a builtin function, operator, or method?
Nächstes Thema: FAQ 7.15 How can I pass/return a {Function, FileHandle, Array, Hash, Method, Regex}?