Re: Turning MARC record object back into a string

[email protected] (Jon Gorman) Mon, 12 Mar 2012 10:28:12 -0500
Newsgroups perl.perl4lib
Message-ID <CABpHuQPH=6Y2g5v5cxkReP8aWF=+SyYtF4VXgu4wpzp3pLzdaw@mail.gmail.com>
> Can anybody think of any reason why I shouldn't just use " my $new_marc = $bib_rec->as_usmarc();". And if you can, can you suggest an alternative way to correctly turn the object into a string?


I'm not sure why you were using sprintf in the first place, so it's a
bit difficult to give too much advice.  When you call ->as_usmarc(),
you get back essentially a "string", a sequence of characters.  It's
not an object.  Also see MARC::File::USMARC encode at
http://search.cpan.org/~gmcharlt/MARC-Record-2.0.3/lib/MARC/File/USMARC.pm#encode%28%29
since that's what this method is a wrapper around.

As a general rule, I wouldn't use sprintf unless I was formatting the
string, which you wouldn't be doing here.  (In general, unlike some
languages, sprintf is probably best used sparingly since using
variable interpolation should take care of most needs.

(ie $mesg = "Something bad happened: $errorcode \n";)

About the only places I use sprintf in perl is formatting numbers.


Jon Gorman