Re: MyLibrary::Resources.pm

2003-10-30 Thread Ed Summers
Hi Eric:

On Tue, Oct 28, 2003 at 03:24:54PM -0500, Eric Lease Morgan wrote:
> Attached is a plain o' documentation file (POD) from the current
> MyLibrary::Resource module. Comments are welcome, and from the synopsis:

Looks like the OOP rewrite is coming along well...and all those nice
tests!

One question about the code I checked out from CVS, it appears that there is a 
t/ and a tests/ directory that contain the same stuff. Also it looks like 
there is some duplication between the lib/ and MyLibrary/ directories. Perhaps 
things were moved at one point?

//Ed


Sybase access from perl

2003-10-30 Thread G.B.Evans
Hi all,

I need to be able to interrogate a Sybase table from within a perl
program.
(The statement would be as simple as SELECT ID FROM TERM_TABLE WHERE
VALUE="a string")

Could some-one point me in the direction of some documentation please.

Geoff.



Geoff Evans
Technical Consultant
Talis Information Ltd.
Birmingham Research Park
Vincent Drive
Birmingham  Phone  +44 (0)121  471  1179
B15 2SQ Fax+44 (0)121  472  0298
United Kingdom  E-Mail [EMAIL PROTECTED]


_
This message has been checked for all known viruses by Star Internet delivered
through the MessageLabs Virus Control Centre. For further information visit
http://www.star.net.uk/stats.asp
_
Any views or personal opinions expressed within this email may not be those of Talis 
Information Ltd.
The content of this email message and any files that may be attached are confidential, 
and for the usage of the intended recipient only. If you are not the intended 
recipient, then please return this message to the sender and delete it. Any use of 
this e-mail by an unauthorised recipient is prohibited.


Re: Sybase access from perl

2003-10-30 Thread Ed Summers
On Thu, Oct 30, 2003 at 04:37:28PM -, G.B.Evans wrote:
> I need to be able to interrogate a Sybase table from within a perl
> program.
> (The statement would be as simple as SELECT ID FROM TERM_TABLE WHERE
> VALUE="a string")

You'll want to use DBI and DBD::Sybase. DBI is Perl's generic interface
to relational databases (Oracle, MySQL, Postgres, InterBase, Informix, 
ODBC, etc). 

The O'Reilly Cheetah [3] is a good investment if you want to get to know
Perl/DBI better.

//Ed

[1] http://search.cpan.org/perldoc/DBI
[2] http://search.cpan.org/perldoc/DBD::Sybase
[3] http://www.oreilly.com/catalog/perldbi/index.html





Updating an array

2003-10-30 Thread Michael Bowden
Hi folks:
 
I first want to apologize for this post.  I think that during the fall
back, I lost a few brain cells.
 
I am working on a Perl script to update a data file.  I load my data
into an array.  I want to cycle through the array and make changes. Then
output the array to a file.  In the past, I would open the database,
read in the lines, and output each line as I updated the elements in the
array.  In these scripts, I was only updating, one element in the array.
 Now I need to update several elements in the array before writing
everything to a file.  If I write the program as I have in the past, I
would be using a lot of i/o reading the data into the array, changing
one element and then outputting the data to a file and repeating the
steps over and over until all the changes have been made.  In some
cases, I will be changing 20 to 30 elements in the array.  So I need
some help.
 
I read in an array from a file.  It looks something like this:
 
200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,
200011122333,,hikls,223,f32,f43,f00,f00,a04,b06,c08,d03,e09,no,no,no,no,no,
mrgreenjeans,,pqrstuv,2244,f20,f00,f00,f00,a06,b08,c10,d10,e00,no,no,no,no,no,
20006654987,,zzzxyxz,33344434,f03,f00,f00,f00,a00,b12,c12,d13,e14,no,no,no,no,no,
 
Each line represents one element in the array.  
So $array[0] equal 
200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,.
 
I want to update the 4th, 5th, and 13th subelements in $array[0],
$array[1] and $array[4].  Then I want to write the updated @array back
to a file.
 
Can some one shed some light on how I can do this without updating a
single line at a time?
 
Thanks.
 
Michael
 
 
 
 
 
Michael L. Bowden
Coordination of Automation and Access Services
Harrisburg Area Community College
e: [EMAIL PROTECTED]


Re: MyLibrary::Resources.pm

2003-10-30 Thread Eric Lease Morgan
Ed wrote:

>> Attached is a plain o' documentation file (POD) from the current
>> MyLibrary::Resource module. Comments are welcome, and from the synopsis:
>> 
> Looks like the OOP rewrite is coming along well...and all those nice tests!
> 
> One question about the code I checked out from CVS, it appears that there is a
> t/ and a tests/ directory that contain the same stuff. Also it looks like
> there is some duplication between the lib/ and MyLibrary/ directories. Perhaps
> things were moved at one point?

Thank you for your support.

I believe I have cleaned up the repository; the MyLibrary and tests
directories no longer exist.

P.S. The code-to-date is also available via cvsweb at:

  http://dewey.library.nd.edu/cgi-bin/cvsweb.cgi/MyLibrary/

-- 
Eric "More Famous Last Words" Morgan
(574) 631-8604




Re: Updating an array

2003-10-30 Thread Brad Baxter
On Thu, 30 Oct 2003, Michael Bowden wrote:

> I read in an array from a file.  It looks something like this:
>
> 200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,
> 200011122333,,hikls,223,f32,f43,f00,f00,a04,b06,c08,d03,e09,no,no,no,no,no,
> mrgreenjeans,,pqrstuv,2244,f20,f00,f00,f00,a06,b08,c10,d10,e00,no,no,no,no,no,
> 20006654987,,zzzxyxz,33344434,f03,f00,f00,f00,a00,b12,c12,d13,e14,no,no,no,no,no,
>
> Each line represents one element in the array.
> So $array[0] equal
> 200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,.
>
> I want to update the 4th, 5th, and 13th subelements in $array[0],
> $array[1] and $array[4].  Then I want to write the updated @array back
> to a file.
>
> Can some one shed some light on how I can do this without updating a
> single line at a time?

Michael,

I'm not sure I follow completely, but the numbered code below illustrates
one approach.  (Your email client might munge the long lines a little.)
I think the point you're making is that you want to read the data file
only once.

Some points:

o This simplified code doesn't open or write to external files, but I
  think you can fill in those blanks.

o I added a line of data, because you say you want to edit $array[4]

o Obviously, your updates won't be "data4", etc.

o If your data file is particularly large, you could read it a line at a
time.  In fact, the following one-liner does the same thing.  :-)

perl -F/,/ -ape \
  'if($.=~/^1|2|5$/){for$i(3,4,12){$F[$i]="data".($i+1);$_=join",",@F}}' \
  datafile

I hope this helps, but again, I may be out of bounds from your actual
needs.

Regards,

Brad

 1  #!/usr/bin/perl
 2  use warnings;
 3  use strict;
 4
 5  my @array = ;
 6  for my $i ( 0, 1, 4 ) {
 7  my @tmp = split( /,/ => $array[ $i ] );
 8  $tmp[ 3 ]  = 'data4';   # 4th
 9  $tmp[ 4 ]  = 'data5';   # 5th
10  $tmp[ 12 ] = 'data13';  # 13th
11  $array[ $i ] = join( ',' => @tmp );
12  }
13  print @array;
14
15  __DATA__
16  200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,
17  200011122333,,hikls,223,f32,f43,f00,f00,a04,b06,c08,d03,e09,no,no,no,no,no,
18  mrgreenjeans,,pqrstuv,2244,f20,f00,f00,f00,a06,b08,c10,d10,e00,no,no,no,no,no,
19  20006654987,,zzzxyxz,33344434,f03,f00,f00,f00,a00,b12,c12,d13,e14,no,no,no,no,no,
20  20006654987,,zzzxyxz,33344434,f03,f00,f00,f00,a00,b12,c12,d13,e14,no,no,no,no,no,

Result:

200044455669,,abcdefg,data4,data5,f00,f00,f00,a01,b23,c45,d00,data13,no,no,no,no,no,
200011122333,,hikls,data4,data5,f43,f00,f00,a04,b06,c08,d03,data13,no,no,no,no,no,
mrgreenjeans,,pqrstuv,2244,f20,f00,f00,f00,a06,b08,c10,d10,e00,no,no,no,no,no,
20006654987,,zzzxyxz,33344434,f03,f00,f00,f00,a00,b12,c12,d13,e14,no,no,no,no,no,
20006654987,,zzzxyxz,data4,data5,f00,f00,f00,a00,b12,c12,d13,data13,no,no,no,no,no,



Re: Updating an array

2003-10-30 Thread Michael McDonnell
Michael Bowden wrote:

Hi folks:

I first want to apologize for this post.  I think that during the fall
back, I lost a few brain cells.
I am working on a Perl script to update a data file.  I load my data
into an array.  I want to cycle through the array and make changes. Then
output the array to a file.  In the past, I would open the database,
read in the lines, and output each line as I updated the elements in the
array.  In these scripts, I was only updating, one element in the array.
Now I need to update several elements in the array before writing
everything to a file.  If I write the program as I have in the past, I
would be using a lot of i/o reading the data into the array, changing
one element and then outputting the data to a file and repeating the
steps over and over until all the changes have been made.  In some
cases, I will be changing 20 to 30 elements in the array.  So I need
some help.
I read in an array from a file.  It looks something like this:

200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,
200011122333,,hikls,223,f32,f43,f00,f00,a04,b06,c08,d03,e09,no,no,no,no,no,
mrgreenjeans,,pqrstuv,2244,f20,f00,f00,f00,a06,b08,c10,d10,e00,no,no,no,no,no,
20006654987,,zzzxyxz,33344434,f03,f00,f00,f00,a00,b12,c12,d13,e14,no,no,no,no,no,
Each line represents one element in the array.  
So $array[0] equal 
200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,.

I want to update the 4th, 5th, and 13th subelements in $array[0],
$array[1] and $array[4].  Then I want to write the updated @array back
to a file.
Can some one shed some light on how I can do this without updating a
single line at a time?

Hi Michael,

Is it really too much i/o to do things as you have described?  It sounds 
like you are reading in the entire file once, and then writing it out 
once.  I cannot imagine how you could do it better than that without 
using a special data file structure (DBM files etc).

Here is what I think you are doing (roughly):

open(INFILE, "someotherfile");
while $line () {
 # perform some operation on the line of data
 $line =~ s|someregularexpression|somereplacement|;
 print OUTFILE $line;
}
close(INFILE);
close(OUTFILE);
# replace the INFILE with the OUTFILE by renaming OUTFILE.
Is that what you are doing?  Or something else?  I think that is about 
as effecient as you can get with i/o without using a datafile on disk 
that has an index (like DBM etc).

Keep in mind that by default your i/o is buffered so PERL won't be 
writing any data at all until it feels it has enough data to make the 
disk i/o worthwhile.  That helps to prevent the system from having too 
many tiny writes to disk.

--
Michael McDonnell, GCIA
[EMAIL PROTECTED]


Re: Updating an array

2003-10-30 Thread Dale Bewley
On Thu, 2003-10-30 at 12:26, Michael Bowden wrote:
> Hi folks:
>  
> I first want to apologize for this post.  I think that during the fall
> back, I lost a few brain cells.
>  
> I am working on a Perl script to update a data file.  I load my data
> into an array.  I want to cycle through the array and make changes. Then
> output the array to a file.  In the past, I would open the database,
> read in the lines, and output each line as I updated the elements in the
> array.  In these scripts, I was only updating, one element in the array.
>  Now I need to update several elements in the array before writing
> everything to a file.  If I write the program as I have in the past, I
> would be using a lot of i/o reading the data into the array, changing
> one element and then outputting the data to a file and repeating the
> steps over and over until all the changes have been made.  In some
> cases, I will be changing 20 to 30 elements in the array.  So I need
> some help.
>  
> I read in an array from a file.  It looks something like this:
>  
> 200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,
> 200011122333,,hikls,223,f32,f43,f00,f00,a04,b06,c08,d03,e09,no,no,no,no,no,
> mrgreenjeans,,pqrstuv,2244,f20,f00,f00,f00,a06,b08,c10,d10,e00,no,no,no,no,no,
> 20006654987,,zzzxyxz,33344434,f03,f00,f00,f00,a00,b12,c12,d13,e14,no,no,no,no,no,
>  
> Each line represents one element in the array.  
> So $array[0] equal 
> 200044455669,,abcdefg,777,f00,f00,f00,f00,a01,b23,c45,d00,e10,no,no,no,no,no,.
>  
> I want to update the 4th, 5th, and 13th subelements in $array[0],
> $array[1] and $array[4].  Then I want to write the updated @array back
> to a file.

Is this remotely close to what you're looking for?

# read data on stdin. collect output on stdout.
while (<>) {
chomp;
@line = split(',');
# interested in records stating with digits
if (/^\d/) {
# update fields 4, 5, 13.
@line[3,4,12] = ('one', 'two', 'three');
print join(',',@line), "\n";
} else {
print "$_\n";
}
}

Alternative to print you could push onto the array of records as you
have been.


>  
> Can some one shed some light on how I can do this without updating a
> single line at a time?
>  
> Thanks.
>  
> Michael
>  
> 
> 
> 
> 
> Michael L. Bowden
> Coordination of Automation and Access Services
> Harrisburg Area Community College
> e: [EMAIL PROTECTED]
-- 
Dale Bewley - [EMAIL PROTECTED] - 530-752-1202
Unix Administrator - Shields Library - UC Davis