CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
printf "modification of a read-only value" error

 



Alaric
New User

Aug 22, 2007, 8:24 PM

Post #1 of 2 (566 views)
printf "modification of a read-only value" error Can't Post

Hey guys,
I'm trying to write a mysql search program for my school's library. However, I had to export their catalog into marc21 format before I could get it into mysql. That is why I wrote this program. As far as I can see, there's nothing wrong with my code, but I've only been working in perl for a few days and I know I could very well be wrong. Can any of you spot the error?


Code
#!/usr/bin/perl -wT 
#

sub ParseTitle
{
local(@titlestrs);
@titlestrs=split(/ \/ /,$_[0]);
$titlestrs[0] =~ s/\.$//;
return $titlestrs[0];
}

sub ParseAuthor
{
$_[0] =~ s/, \d\d\d\d-\d{0,4}$//;
$_[0] =~ s/\.$//;
return $_[0];
}

sub ExportToText
{
$File=$_[0];
$record=$_[1];
unless(defined $File and defined $record)
{
return -1;
}
$titlefield=$authorfield=$callnumfield=$publisherfield=$subjstr=undef;
$titlefield=$record->field('245') ? $record->field('245') : undef;
$authorfield=$record->field('100') ? $record->field('100') : undef;
$callnumfield=$record->field('900') ? $record->field('900') : undef;
$publisherfield=$record->field('260') ? $record->field('260') : undef;
@subjectlist=$record->field('650') ? $record->field('650') : undef;
$callstr= defined $callnumfield ? $callnumfield->as_string() : "unknown";
$titlestr= defined $titlefield ? ParseTitle($titlefield->as_string()) : "unknown";
$authorstr= defined $authorfield ? ParseAuthor($authorfield->as_string()) : "unknown";
$publisherstr= defined $publisherfield ? $publisherfield->as_string() : "unknown";

#print "$callstr\t$titlestr\t$authorstr\t$publisherstr\n";

print $titlestr."\n";

printf $File $callstr;
printf $File "\t";
printf $File $titlestr; #line 44
printf $File "\t";
printf $File $authorstr;
printf $File "\t";
printf $File $publisherstr;

foreach $subjectfield (@subjectlist)
{
$subjstr= defined $subjectfield ? $subjectfield->as_string() : "unknown";
printf $File "\t$subjstr";
}
printf $File "\n";
return 0;
}

use warnings;
use strict;
use MARC::Batch;
use DBI;

my $batch =MARC::Batch->new('USMARC','/home/alaric/microlif.001');

my $File;
open($File,">out.dat") or die "Could not write output file!";

while (my $thisrecord = $batch->next())
{
ExportToText($File,$thisrecord);
}


here's the output to my program and the error in question.


Code
... 
Witches, wit, and a werewolf; retold by Jeanne B. Hardendorff. Illustrated by Laszlo Kubinyi
Greek and Roman mythology
Irish sagas and folk-tales
Urban legends : the truth behind all those delisioulsy entertaining myths that are absolutley, positively, 100% not true!
Modification of a read-only value attempted at ./MARCToText.pl line 44.


p.s., if you can't tell, I'm running linux (Ubuntu 7.04) if it makes a difference. Also, my perl interpreter is version v5.8.8 built for i486-linux-gnu-thread-multi.


(This post was edited by Alaric on Aug 22, 2007, 8:25 PM)


KevinR
Veteran


Aug 22, 2007, 9:11 PM

Post #2 of 2 (563 views)
Re: [Alaric] printf "modification of a read-only value" error [In reply to] Can't Post

chnage all instances of "printf" to "print" and see if that helps.
-------------------------------------------------

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives