Perl OS system equivalence or Perl scripts for UNIX-and-Windows

2006-05-25 Thread benbart
Hi all,

I've inherited a bunch of scripts that am spending lots of time debugging and
tracing, changing etc. Part of the task also is to have the same modified in
some way so that I can use it for both UNIX and Windows.

Lots of these scripts have system "" on them which of course I
can't run on Windows. Can anyone suggest how to get around this? Or any white
papers on how to do this?

I will be interested to know if there is a white paper of sort that discuss how
to write a Perl script with the intention of wanting to use that script for
both UNIX and Windows with the most minimal changes of sort if there will be
some changes required.

Any response or advise will be very much appreciated. Thanks in advance ...


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to convert these tablespace output report into a delimited file, csv or tilde

2006-06-21 Thread BenBart

Hi all,

Can anyone suggest what is the best way to convert the lines of text 
between the = into a delimited file?


Do I have to read the lines one at a time and append the delimiter that 
I wanted into the end of each line and then re-direct the output to a 
file? FYI, the line "Tablespaces for Current Database" is like the 
heading so the start of each record is at the line Tablespace ID.


My real objective is to convert this output into a delimited file of 
tablespace records where the starting field of the record is the 
Tablespace ID line and the ending field of the record is the Number of 
Containers. The lines Detailed explanation: and Normal are not part of 
the record.


Will I be better off using a UNIX script instead and awk+sed

Thanks in advance...




  Tablespaces for Current Database

Tablespace ID= 0
Name = SYSCATSPACE
Type = System managed space
Contents = Any data
State= 0x
  Detailed explanation:
Normal
Total pages  = 32849
Useable pages= 32849
Used pages   = 32849
Free pages   = Not applicable
High water mark (pages)  = Not applicable
Page size (bytes)= 4096
Extent size (pages)  = 32
Prefetch size (pages)= 32
Number of containers = 1

Tablespace ID= 1
Name = TEMPSPACE1
Type = System managed space
Contents = System Temporary data
State= 0x
  Detailed explanation:
Normal
Total pages  = 1
Useable pages= 1
Used pages   = 1
Free pages   = Not applicable
High water mark (pages)  = Not applicable
Page size (bytes)= 4096
Extent size (pages)  = 32
Prefetch size (pages)= 32
Number of containers = 1

Tablespace ID= 2
Name = USERSPACE1
Type = System managed space
Contents = Any data
State= 0x
  Detailed explanation:
Normal
Total pages  = 12858
Useable pages= 12858
Used pages   = 12858
Free pages   = Not applicable
High water mark (pages)  = Not applicable
Page size (bytes)= 4096
Extent size (pages)  = 32
Prefetch size (pages)= 32
Number of containers = 1

Tablespace ID= 3
Name = TEMPSPACE08K
Type = System managed space
Contents = System Temporary data
State= 0x
  Detailed explanation:
Normal
Total pages  = 1
Useable pages= 1
Used pages   = 1
Free pages   = Not applicable
High water mark (pages)  = Not applicable
Page size (bytes)= 8192
Extent size (pages)  = 32
Prefetch size (pages)= 32
Number of containers = 1

Tablespace ID= 4
Name = TEMPSPACE32K
Type = System managed space
Contents = System Temporary data
State= 0x
  Detailed explanation:
Normal
Total pages  = 1
Useable pages= 1
Used pages   = 1
Free pages   = Not applicable
High water mark (pages)  = Not applicable
Page size (bytes)= 32768
Extent size (pages)  = 32
Prefetch size (pages)= 32
Number of containers = 1

Tablespace ID= 5
Name = TSINTI03
Type = Database managed space
Contents = Any data
State= 0x
  Detailed explanation:
Normal
Total pages  = 125
Useable pages= 122
Used pages   = 20
Free pages   = 102
High water mark (pages)  = 20
Page size (bytes)= 8192
Extent size (pages)  = 2
Prefetch size (pages)= 2
Number

how to avoid "spawning" multiple process of the same script ..

2006-07-05 Thread BenBart

Hi all,

How do I prevent multiple instance of the same script from running?

That is for example, if I have a script named script1.pl and it is 
already running, I want the script to be able to check that it is 
already running and then just exit ...


Is this possible to do in both UNIX and Windows?



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Perl's fork ... any example please ...

2006-07-05 Thread BenBart

Hi all,

Am getting confused on how to use fork, does anyone have an example on 
how to use this or where and what is it used for  ???


Not sure if this is what I needed  Is fork the equivalent of running 
the UNIX wait command when writing a UNIX script where you want to make 
sure that the run of a previous command finishes its run before you can 
the next command?


Thanks in advance ...



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Perl's system "[OS_COMMAND]"

2006-07-05 Thread BenBart

Hi all,

Is there another option of running an OS command or UNIX script besides 
using system "[OS_COMMAND]", for example system "cat /etc/hosts" or 
system "[UNIX_SCRIPT]"?


How can I make sure that the system '[OS_COMMAND]" finishes its run 
before I proceed to run the rest of the codes in the script?


Thanks in advance ...



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




BASEDIR and BASENAME on Windows

2006-08-01 Thread BenBart

Hi all,

Can anyone please tell me how to get the BASENAME and BASEDIR of a file 
... i.e. for example, if I have C:\Windows\Temp\Dir1\MyFile.TXT, I want 
to be able to get the BASENAME which is MyFile and the BASEDIR which is 
C:\Windows\Temp\Dir1 and assign them to variables ...


Thanks in advance ...



--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Dynamic variables - from INI files ...

2006-08-11 Thread benbart
Hi,

I am writing a Perl script that reads some kind of INI file. I cannot use
Config::INI or install any new modules due to some restriction so am reading
the whole INI text file one line at a time and storing them into an array. Here
are what on my INI files:

FTP_USER=FTPUser
FTP_PASSWORD=FTPUser
FTP_MODE=binary
FTP_TARGET_SERVER=FTPSERVER
FTP_ACTION_DIR=C:\FtpAction
FTP_LOGPATH=C:\Temp
NUM_OF_DIRS=2
DEFAULT_TARGET_DIR=C:\Temp
SOURCE_DIR1=D:\Study\Perl\MyFtp
SOURCE_DIR2=D:\Study\Perl
TARGET_DIR1=C:\Dir1
TARGET_DIR2=C:\Dir2

Because I cannot install new modules, am not using Net::Ftp as well and instead
creating an FTP batch file which I then execute as #system "ftp -v -n -i
-w:8192 -s:$FTP_BATCHFILE";

So far so good. Now I want to change my Perl script so that I can parse the path
of the source file and whether it matches SOURCE_DIR1 or SOURCE_DIR2 and if so
use TARGET_DIR1 or TARGET_DIR2 respectively on the FTP Server otherwise use
DEFAULT_TARGET_DIR.

I am running the script as MyFtp.pl "D:\Study\Perl\Myftp\Test1.JPG", so I check
if ARGV[0] matches the string of SOURCE_DIR1 and if so use C:\Dir1 as the
target directory when I create the FTP batch file.

At the moment, I am hardcoding the checks as something like ...

if path = $SOURCE_DIR1 then TARGET_DIR=$TARGET_DIR1
elif path = $SOURCE_DIR2  TARGET_DIR=$TARGET_DIR2
else TARGET_DIR=$DEFAULT_TARGET_DIR

Of course, the above is not the program code but am sure the gurus understand
what I mean. Unfortunately, if I have to add two more directories to check for
example, SOURCE_DIR3, SOURCE_DIR4  SOURCE_DIR[N] and TARGET_DIR3,
TARGET_DIR4 ... TARGET_DIR[N], then I have to check my Perl script. So, what I
want to be able to know is if it is possible to load the values of SOURCE_DIR1
to SOURCE_DIR[N] into an array, and if so, how? I want to know if I can create
a dynamic variables $SOURCE_DIR$[N] that I can load into the array, I know what
is  the final [N] since I have NUM_OF_DIRS=2. I am wanting to do something that
will look like this:


   my $count=1;
   my $source_array=()
   my $target_array=()
   while ( $count le $NUM_OF_DIRS )
   {
  $source_array[$count]=$SOURCE_DIR$count;
  $target_array[$count]=$TARGET_DIR$count;
  #print $count . "\n";
  #print $regex . "\n";
  #if ($path =~ m/$regex/) {
  #  print 'match';
  #} else {
  #  print 'no match';
  #}
  $count++;
   }

Then somewhere down the code, I do

   my $count=1;
   while ( $count le $NUM_OF_DIRS )
   {
  if ($path =~ m/$source_array[$count]/) {
TARGET_DIR=$target_array[$count];
  } else {
TARGET_DIR=$DEFAULT_TARGET_DIR;
  }
  $count++;
   }

Obviously, this is not working at the moment, can someone on the list please
advise if what I am trying to achieve is possible or not. If it is possible but
am not creating or parsing the variables correctly, please advise on how I
should be doing it. I have no problem evaluating each value of the INI files,
i.e. I can parse $SOURCE_DIR1, $SOURCE_DIR2, $NUM_OF_DIRS etc., I just want to
know how I can dynamically create a variable $SOURCE_DIR1 to $SOURCE_DIR[N] and
store them into an array or perhaps how to check if a variable has been defined
or not?

Thanks in advance.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to search/match a variable pattern

2006-08-11 Thread benbart
Hi all,

Can some please advise how to get this to work?

   print "matches" if $string =~ m/$pattern/;

Am trying to search for a pattern but the pattern has to be a variable. Thanks
in advance.


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How to search/match a variable pattern

2006-08-11 Thread benbart

Hi John,

Thanks for a very quick response John.

It gives the error as below:

Trailing \ in regex m/D:\STUDY\PERL\MYFTP\/ at 
D:\Study\Perl\MyFtp\Ftp1.pl line

109.

($base,$path,$type) = fileparse($ARGV[0]);
$pattern=$path;
print "matches" if $string =~ m/$pattern/;

I print $pattern and it is D:\STUDY\PERL\MYFTP\. You are probably that 
there are

some meta-characters, \ :, that I need to escape, but how do I escape them if
they are variables?

Also, how do I do a non-case sensitive match. At the moment, am using uc() to
upper case both the string and the pattern that I am searching for.


Quoting "John W. Krahn" <[EMAIL PROTECTED]>:


[EMAIL PROTECTED] wrote:

Hi all,


Hello,


Can some please advise how to get this to work?

   print "matches" if $string =~ m/$pattern/;

Am trying to search for a pattern but the pattern has to be a 
variable. Thanks

in advance.


How did this "not work"?  What is it not doing that you want it to do?  What
warning/error messages did it generate?

You probably have regex meta-characters in $pattern that need to be escaped.


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How to search/match a variable pattern

2006-08-11 Thread benbart

Hi John,

Thanks for a very quick response John.

It gives the error as below:

Trailing \ in regex m/D:\STUDY\PERL\MYFTP\/ at 
D:\Study\Perl\MyFtp\Ftp1.pl line

109.

($base,$path,$type) = fileparse($ARGV[0]);
$pattern=$path;
print "matches" if $string =~ m/$pattern/;

I print $pattern and it is D:\STUDY\PERL\MYFTP\. You are probably right that
there are some meta-characters, \ :, that I need to escape, but how do 
I escape

them if they are variables? Basically, I actually just want to search for
whether I found a match of a particular string on $path and do not need to
assign it to $string, how do I do that? Am not sure if am doing it right
really, so in theory, I just want to do something like this ...

if ($path =~ m/$pattern/) {
  print 'match';
  ... do something here ...
} else {
  print 'no match';
  ... do something here ...
}

Or do I get the regex logic all wrong ...

The one liner is just a test on whether am using the pattern matching 
correctly

or not.

Also, how do I do a non-case sensitive match. At the moment, am using uc() to
upper case both the string and the pattern that I am searching for.


Quoting "John W. Krahn" <[EMAIL PROTECTED]>:


[EMAIL PROTECTED] wrote:

Hi all,


Hello,


Can some please advise how to get this to work?

   print "matches" if $string =~ m/$pattern/;

Am trying to search for a pattern but the pattern has to be a 
variable. Thanks

in advance.


How did this "not work"?  What is it not doing that you want it to do?  What
warning/error messages did it generate?

You probably have regex meta-characters in $pattern that need to be escaped.


John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Running system command or batch file using system "[command]"

2006-08-12 Thread benbart
Hi all,

Using Perl on Windows, at the moment am running commands and batch files using
system "[OS COMMAND]/[BATCH FILE]", can someone tell me how can I check for the
success or failure of running the command, i.e. like a return code in UNIX.
Also, is there a better alternative to running OS commands or BATCH files
besides the system command.

Thanks ...




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to emulate this set or how to assign the result of running system "command" to a variable

2006-08-13 Thread benbart
Hi all,

I currently have a MS-DOS batch file that am trying to convert to a Perl script.
I have something like this in the .BAT file where variables are "set" based on
some parsing of a variable passed as a command line argument whenever the .BAT
file is executed by the application.

The command line variable is parsed/cut-down-into pieces of source_drive,
source_root, source_file, source_extn and source_path as the contents of the
.BAT file shows below:



rem creates a ftp command file on the root directory of the drive.
set ftp_action=%~dp0%~n1.ftp

rem these aren't used here for debuging purposes
set source_drive=%~dp0
set source_root=%~dp1
set source_file=%~n1
set source_extn=%~x1
set source_path=%~p1

rem get the file path
set destination_path=%~p1



Can someone tell me how can I achieve what the .BAT file is currently trying to
do in a Perl script? I tried doing system "set source_drive=%~dp0"; or
$source_drive=system "set source_drive=%~dp0";to try and assign the output of
the set command to a variable but that does not seem to work? I do not get the
result that am expecting which is the value of %~dp0, instead I presume am
getting more like the return code of running the system "set
source_drive=%~dp0".

Can someone please advise on what am doing wrong and what must I be doing
instead?

I may have to do the same thing for converting UNIX Ksh script to Perl script.
And checking the Ksh script, there is a lot of UNIX commands executed from
within the Ksh script that assigns that output of UNIX commands to variable,
for example, server=`hostname`, I cannot work out how I should be doing this on
Perl, I tried $server=system "hostname" and that does not work as $server when I
try to print it gives 0 (zero) which I think is more like the return code for
running system "hostname" and not the result that am after which is the
hostname of the server.

Thanks in advance.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Re: How to emulate this set or how to assign the result of running system "command" to a variable

2006-08-13 Thread benbart

Hi John,

Thanks for your prompt response as usual ...

Not exactly need File::Spec and File::Basename per se, I really need to grab
some of the environment variables that are set when the Perl script is run or
in the case of the .BAT file, when the batch file is run. For example, I want
to know what is %TEMP% and if it is C:\WINDOWS\TMP, I want to change it to
C:\TEMP instead whenever I run by script by doing SET TEMP=C:\TMP, but this is
all straightforward in the batch file but am confused on how to do it inside
Perl.

For using ...

use Sys::Hostname;
my $server = hostname;

The above one is only for the hostname? In some of the existing UNIX 
scripts, I

have num_of_developers=`cat /etc/passwd | grep developer | wc -l` which gives
the number of developer logins. So how do I get it to do the same in Perl? I
tried $num_of_developers=system "cat /etc/passwd | grep developer | wc -l",
that doesn't work and I think I understand that Perl is giving the return code
of running the system function. So how do I get Perl to give the resultset of
running the OS commands that I passed on to system?

Quoting "John W. Krahn" <[EMAIL PROTECTED]>:


[EMAIL PROTECTED] wrote:

Hi all,


Hello,

I currently have a MS-DOS batch file that am trying to convert to a 
Perl script.
I have something like this in the .BAT file where variables are 
"set" based on
some parsing of a variable passed as a command line argument 
whenever the .BAT

file is executed by the application.

The command line variable is parsed/cut-down-into pieces of source_drive,
source_root, source_file, source_extn and source_path as the contents of the
.BAT file shows below:


You probably want File::Spec and File::Basename:

perldoc File::Spec
perldoc File::Spec::Win32
perldoc File::Basename


[snip]

Can someone tell me how can I achieve what the .BAT file is 
currently trying to

do in a Perl script? I tried doing system "set source_drive=%~dp0"; or
$source_drive=system "set source_drive=%~dp0";to try and assign the 
output of
the set command to a variable but that does not seem to work? I do 
not get the

result that am expecting which is the value of %~dp0, instead I presume am
getting more like the return code of running the system "set
source_drive=%~dp0".


perldoc -f system



Can someone please advise on what am doing wrong and what must I be doing
instead?

I may have to do the same thing for converting UNIX Ksh script to 
Perl script.

And checking the Ksh script, there is a lot of UNIX commands executed from
within the Ksh script that assigns that output of UNIX commands to variable,
for example, server=`hostname`, I cannot work out how I should be 
doing this on
Perl, I tried $server=system "hostname" and that does not work as 
$server when I
try to print it gives 0 (zero) which I think is more like the return 
code for

running system "hostname" and not the result that am after which is the
hostname of the server.


use Sys::Hostname;

my $server = hostname;



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 






--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to emulate set -x on Perl ...

2006-08-13 Thread benbart
Hi all,

In UNIX, we run set -x as some kind of DEBUG mode, how do we do the same in
Perl?




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Comparing two files of 8million lines/rows ...

2006-08-16 Thread benbart
Hi all,

I have two database tables, one is local and one is on a WAN. They are supposed
to be in-sync but they at the moment, they are not. There are 8million+ plus
rows on this table.

I tried to do SELECT EMPNO FROM EMP WHERE EMPNO NOT IN ( SELECT EMPNO FROM
[EMAIL PROTECTED] ), leave that running for hours and all thru the night and 
guess
what, am still waiting for the result to come out ...

So what I decided is I want to extract the records into a flat file and then
write a Perl script to skim thru each line and check whether it exists on the
other file. While there will be 8million+ lines, the file will not be big
beacuse am only extracting one-column from the table.

Does anyone have an existing Perl code that does a similar thing like this
already? It will be much appreciated if you can send it to me and then I will
just modify it accordingly.

Example logic that I have is this:

FILE1:
MICKEY
MINNIE
DONALD
GOOFY
PLUTO

FILE2:
MICKEY
MINNIE
DONALD
GOOFY
PLUTO
BUGS-BUNNY

So search FILE1 for all line entries of FILE2 then output whoever does not exist
into FILE3. So after running the script, I should have ...

FILE3:
BUGS-BUNNY

What I currently have is that I read all of FILE2's entries into an array? Read
FILE1 one line at a time using m/// and if there is no m///, print that to
FILE3.

It seems to work fine for 1000 lines of entries, but am not particularly sure
how long will that take for 8million+ rows, not even sure if I can create an
array to contain 8million+ plus rows, if I can't, then am back to doing this on
the database instead. Another option am looking at is just to read FILE1 one
line at a time and do a grep "$string_to_search" FILE2 but I do not know how to
do a grep-like syntax against a file on Perl especially if the search string is
a variable.

Why I prefer using a script is so am not putting loads into the database not to
mention that I can put more logic into the script than on the SQL statement.

Any advise or other options will be very much appreciated  Thanks in
advance.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How do I do this on Perl ...

2006-08-22 Thread benbart
Hi all,

I used to do this on UNIX scripts ...

#!/usr/bin/ksh
vowels="a e i o u"
for letter in $vowels
do
   echo $letter
done

How do I do the same in Perl?

Is it possible to do this in Perl without having to put vowels into an array and
use foreach, i.e., using only a FOR-LOOP, but not necessarily having to hardcode
the ending number as for($start=1;$start<=5;$start++)? vowels may change into
letters="a b c d e f g h" in which case for($start=1;$start<=5;$start++) may
not be valid anymore.

Any feedback will be very much appreciated  Thanks in advance ...












-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to do this sed one-liners inside Perl?

2006-08-23 Thread benbart
Hi all,

I found the following sed one-liner trick that strips out the spaces that I run
as follows:

sed 's/^[ \t]*//;s/[ \t]*$//' /tmp/file.txt > /tmp/filea.txt

This strips out the spaces in file.txt and cuts down its size from 600M+ to a
mere 60M. How do I apply this sed one-liner trick inside Perl in the most
easisest way? At the moment am running it via system "sed 's/^[ \t]*//;s/[
\t]*$//' /tmp/file.txt > /tmp/filea.txt"? Am sure you should be able to do this
without using system, can someone suggest how? Thanks in adbvance.

#sed one-liner tricks:
#   http://sed.sourceforge.net/sed1line.txt
#   http://www.pement.org/sed/sed1line.txt

#delete leading whitespace (spaces, tabs) from front of each line, aligns all
text flush left

 sed 's/^[ \t]*//'

#
# delete trailing whitespace (spaces, tabs) from end of each line

 sed 's/[ \t]*$//'

#
# delete BOTH leading and trailing whitespace from each line

 sed 's/^[ \t]*//;s/[ \t]*$//'




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to grep $string from a file? How to run sed-like commands from Perl?

2006-08-23 Thread benbart
Hi all,

Please note the Perl script that am trying to write at end the of this email,
after the dashes.

I have two files that contains thousands and millions of records of two database
tables that are supposed to be replicated and same "similar" amount of records
but, unfortunately, they're not.

This is what's happening:

TARGET1.LOG:
2
4
6

SOURCE1.LOG:
1
2
3
4
5
6

I place all of TARGET1.LOG into an array, then I read SOURCE1.LOG one line at a
time and do a grep against the array. If there is no match, then that means the
record does not exist and is thus not replicated and I will want to print this
into a file or maybe store it into an unmatch array temporarily and write the
whole array into a file later on.

The script does what it intends to do for small-sized file. But when I get a
file with 8million+ records that is 600MB in size. It consumes a lot of the CPU
system resource. Stripping the spaces manually via sed cuts the size down to
60MB, but it still consumes a lot of resource. So now I want to know how can I
convert this script to grep the string from a file instead of from the array.
Doing so I think will lessen the use of most of the CPU resource.

Am guessing that I have to take out the array bit and just modify this line
here:

@match=grep{/$lookfor/[EMAIL PROTECTED];

But I am not sure how or what I should change it to. How do I tell grep to
search from a file instead of from an array? Do I need to open a FILEHANDLE for
grep to search from? Also, I want to do the sed stripping of the spaces from
within Perl instead of what am currently doing which is running the sed
manually first as a separate step and then running my Perl script.

Any help will be very much appreciated. Thanks in advance.

---

#!/usr/bin/perl
my $data_file = 'target1.log';
open DATA, "$data_file" or die "can't open $data_file $!";
my @array_of_data = ;
close (DATA);
print "The array MAX index is ==> $#array_of_data ...\n";

open (DATA, "< source1.log");
while(  )
{
   #print $_;
   chomp $_;
   $lookfor=$_;

   @match=grep{/$lookfor/[EMAIL PROTECTED];
   if (@match) {
  print "MATCH :: << $lookfor >> \n";
   }
   else
   {
  print "NO-MATCH :: << $lookfor >> \n";
   }
}
close (DATA);

exit;





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to remove duplicates from a file ...

2006-08-23 Thread benbart
Hi all,

If I have a file that has ...

A
A
B
C
D
D
D
E
E
F
F
G

How do I remove the duplicates via a Perl script?




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to chek the nth column of a delimited file

2006-09-10 Thread benbart
Hi all,

I have to re-process a delimited file but I only need to proceed records from
the file that satisfy a specific condition. Can someone advise what is the best
way to do this? For example, if I have this file here 


A~BB~CCC~DDD~~D~
A~BB~CCC~DDD~~D~
A~BB~CCC~DDD~~U~
A~BB~CCC~DDD~~D~
A~BB~CCC~DDD~~D~
A~BB~CCC~DDD~~U~
A~BB~CCC~DDD~~D~
A~BB~CCC~DDD~~D~

This file has already been processed, but somehow records where the 6th column =
D are not processed, so I want to re-run the Perl script but I only want to
process the records for when the 6th column = D.

Any suggestions will be very much appreciated. Thanks in advance.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




DBI - DB2 Perl Script ... TWiki

2006-09-28 Thread benbart
Hi all,

I have this script that am trying to use to connect to DB2.

At the moment I cannot get the script to connect to DB2.

In the UNIX prompt, if I run . /home/db2inst1/sqllib/db2profile first and then
run the Perl script, then I can connect to DB2.

Also, I can only do export DB2INSTANCE=db2inst1 and then run the Perl script,
then I can connect to DB2.

Can someone please advise how do I do an export DB2INSTANCE=db2inst1 or run the
. /home/db2inst1/sqllib/db2profile and that does not work? I tried to include
the following lines within the Perl script and it does not work too ...

system ". /home/db2inst1/sqllib/db2profile";
system "export DB2INSTANCE=db2inst1";

Any tips on how to get this to work will be very much appreciated. FYI, am
mainly trying to get this to work for Twiki.


=


#!/usr/bin/perl

# $Id: test.pl,v 11.7 2004/02/01 11:16:16 timbo Exp $
#
# Copyright (c) 1994-1998 Tim Bunce
#
# See COPYRIGHT section in DBI.pm for usage and distribution rights.


# This is now mostly an empty shell I experiment with.
# The real tests have moved to t/*.t
# See t/*.t for more detailed tests.


#use DBI;

use DBI::DBD;   # simple test to make sure it's okay

use Config;
use Getopt::Long;
use strict;

#use DBI;
#use DBD::DB2::Constants;
use DBD::DB2;

#system ". /home/db2inst1/sqllib/db2profile";
#system "env > /tmp/env.txt";
#system "export DB2INSTANCE=db2inst1";

#$dbh = DBI->connect("dbi:DB2:db_name", $username, $password);
#$dbh = DBI->connect("dbi:DB2:DBNIAA01", "db2inst1", "eriver96");
#my $string="DBNIAA01";
my $string="dbi:DB2:DBNIAA01";
#my $string="dbi:DB2:DBMSDATA";
my $user="db2inst1";
my $pass="eriver96";
my $db="DBNIAA01";
my $hostname="svniadb.at.police.govt.nz";
my $port="5";

#my $string = "dbi:DB2:DATABASE=$db; HOSTNAME=$hostname; PORT=$port;
PROTOCOL=TCPIP; UID=$user; PWD=$pass;";
my $dbh = DBI->connect($string, $user, $pass) || die "Connection failed with
error: $DBI::errstr";

if (!defined($dbh)) {
print "Crap, am exiting ??? \n";
exit; }

#my $stmt = "select current timestamp from sysibm.sysdummy1;";
my $stmt = "select * from nia.mstr_config;";
my $sth = $dbh->prepare($stmt);
$sth->execute();

while( my @array = $sth->fetchrow_array ) {
 print "$array[0]\n";
}

#print "$string\n";
#my $dbh = DBI->connect($string, $user, $pass) || die "Connection failed with
error: $DBI::errstr";

$sth->finish();
  $dbh->disconnect();



-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




DatabasePlugin for DB2 and SQLSERVER on TWiki ...

2006-09-28 Thread benbart
Hi all,

Am trying to setup TWiki to connect to DB2 and SQLSERVER and needs to configure
the DatabasePlugin.pm and DatabasePluginConfig.pm. So far, am not having any
luck with them. Already, the notes/docs said the plugin had been tested on
MySQL and ORACLE databases only but since I was able to write a simple Perl
script to connect to DB2, I am hoping it will work with DB2 as well.

Anyway, I will be interested to hear from anyone who had managed to configure
these Perl modules to connect to DB2 and SQLSERVER databases.

Thanks in advance.




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Just asking ... why the dot or no dot

2006-10-18 Thread benbart
Hi all,

Just want to know what really is the difference when running a script as

. myscript or simply myscript, i.e. the first one with a dot infront of it and
the other one without a dot.

Or does it matter only when invoking the script from within a script?

Any thoughts will be very much appreciated. Thanks in advance.





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




How to parse UNIX commands ...

2006-10-26 Thread benbart
Hi all,

How do I parse or evaluate the output of UNIX commands?

For example, in UNIX scripts, I can run filesystem=`df -k | awk -F"" ' { print
$6 }'` to check for the mount points.

How do I achieve the same in Perl? That is, I tried:

#!/usr/bin/perl
$x=system 'df -k';
print "= \n";
print $x . "\n";

And I am hoping that I can same the results of the df -k output into some kind
of variable that I can then parse and arrange into some format to check for
what logical volumes is mounted into what filesystems etc.

But x gives I believe the result of whether running the system command is
successful or not.

Maybe I can just simply run system 'df -k', re-direct that into some output file
and then parse it using OPEN-CLOSE filehandles. Is there any easier way of doing
this?

I am not just wanting to do this for the df -k command but also for executing ls
-l | wc -l maybe and some other UNIX commands.

Any advise will be very much appreciated. Thanks 




-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
 




Perl connecting to Oracle and SQL Server databases ...

2006-12-17 Thread Benbart

Hi all,

Does anyone know of any resource that I can go to for example on 
connecting to Oracle and Microsoft SQL Server databases using Perl 
??? I need more than connecting to the database, some example on how 
to do SELECT, INSERT, UPDATE and DELETE will be very helpful as well.


Thanks in advance ...





--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]