Re: MARC::Record leader

2003-09-19 Thread Ed Summers
On Fri, Sep 19, 2003 at 07:58:01PM +0530, Saiful Amin wrote:
 I never had to worry about the record_length (pos 00-04) or the
 base_address (pos 12-16) in the leader.  I think they are automagically
 updated while writing the record via $rec-as_usmarc().

saiful++

Yes, they should be automatically calculated when writing the file as marc.

print $record-as_usmarc();

Albeit, this method should really be as_marc() or as_marc21() but there you go
:)

//Ed


Re: MARC::Record leader

2003-09-11 Thread Ed Summers
On Thu, Sep 11, 2003 at 08:40:48AM -0500, Chuck Bearden wrote:
 I hope this helps.

This helps for the order of the fields, but from looking at his program it looks
like the more pernicious problem is the order of the subfields within each
field!

//Ed


MARC::Record leader

2003-09-10 Thread Joshua Ferraro
Hello everyone,
I am new to this list.  I'm also very new to Perl so please bear with me:-).
I am working on a Z3950 Server for my library (which is using Koha for ILS) and
I am having trouble generating MARC records using MARC::Record.  I am generatingthe 
records from a MySQL database and I don't know how to determine on-the-fly
what the leader length and base address are (also I'm not sure how to use the
set_leader_lengths access method).

My code is below...any suggestions?

Thanks,

Joshua Ferraro
Nelsonville Public Library

Here is my code(this sub should build one record from Koha's marc_subfield_table
using one bibid stored in @bib_list):

sub fetch_handler {
my ($args) = @_;
# warn in fetch_handler;  ## troubleshooting
my $offset = $args-{OFFSET};
$offset -= 1;   ## because $args-{OFFSET} 1 = record #1
chomp (my $bibid = $bib_list[$offset]);
my $sql_query = SELECT tag, subfieldcode, subfieldvalue FROM marc_subfi
eld_table where bibid=?;
my $sth_get = $dbh-prepare($sql_query);
$sth_get-execute($bibid);

## create a MARC::Record object
my $rec = MARC::Record-new();

## create the fields
while (my @data=$sth_get-fetchrow_array) {

my $tag = $data[0];
my $subfieldcode = $data[1];
my $subfieldvalue = $data[2];

my $field = MARC::Field-new(
  $tag,'','',
  $subfieldcode = $subfieldvalu
e,
);

$rec-append_fields($field);

## build the marc string and put into $record
my $record = $rec-as_usmarc();
$args-{RECORD} = $record;
}


Re: MARC::Record leader

2003-09-10 Thread Ed Summers
On Wed, Sep 10, 2003 at 01:57:31PM -0400, Joshua Ferraro wrote:
 sub fetch_handler {
 my ($args) = @_;
 # warn in fetch_handler;  ## troubleshooting
 my $offset = $args-{OFFSET};
 $offset -= 1;   ## because $args-{OFFSET} 1 = record #1
 chomp (my $bibid = $bib_list[$offset]);
 my $sql_query = SELECT tag, subfieldcode, subfieldvalue FROM marc_subfi
 eld_table where bibid=?;
 my $sth_get = $dbh-prepare($sql_query);
 $sth_get-execute($bibid);
 
 ## create a MARC::Record object
 my $rec = MARC::Record-new();
 
 ## create the fields
 while (my @data=$sth_get-fetchrow_array) {
 
 my $tag = $data[0];
 my $subfieldcode = $data[1];
 my $subfieldvalue = $data[2];
 
 my $field = MARC::Field-new(
   $tag,'','',
   $subfieldcode = $subfieldvalu
 e,
 );
 
 $rec-append_fields($field);
 
 ## build the marc string and put into $record
 my $record = $rec-as_usmarc();
 $args-{RECORD} = $record;
 }


The call to as_usmarc() will populate the record length for you. So you
shouldn't have to do it yourself when building a record on the fly. We're you
getting an error somewhere about the record length not being populated?

Your code looks to be creating a bunch of fields each with one subfield in them.
This is not correct. Furthermore, it is unlikely that the order that the
subfields come back from MySQL is the order in which you will want to build your
field...but I may be wrong there (not knowing Koha). I'm sure the Koha folks
have some utility for dumping their database as MARC don't they? If not they
should :)

//Ed