Re: MARC-perl: different versions yield different results

[email protected] (Ed Summers)
Newsgroups perl.perl4lib
Message-ID <[email protected]>
Hi Leif,

Is the downside to this approach that you are modifying a CPAN module
in place, or is it something to do with the behavior of 'use bytes'?
Would there be any undesirable side effects to adding 'use bytes' to
MARC::File::USMARC::encode on CPAN?

//Ed

On Tue, Oct 12, 2010 at 7:58 AM, Leif Andersson
<[email protected]> wrote:
> Myself I have changed one of the modules.
>
> MARC::File::USMARC
> It has a function called encode() around line 315
> I have added a "use bytes;" just before the final return. Like this:
>
> use bytes;
> return join("",$marc->leader, @$directory, END_OF_FIELD, @$fields, END_OF_RECORD);
>
> To change directly in code like this is totally "no-no" to many programmers.
> If you feel uncomfortable with this, there are other methods doing the same stuff.
> You could write a package:
>
> package MARC_Record_hack;
> use MARC::File::USMARC;
> no warnings 'redefine';
> sub MARC::File::USMARC::encode() {
>    my $marc = shift;
>    $marc = shift if (ref($marc)||$marc) =~ /^MARC::File/;
>    my ($fields,$directory,$reclen,$baseaddress) = MARC::File::USMARC::_build_tag_directory($marc);
>    $marc->set_leader_lengths( $reclen, $baseaddress );
>    # Glomp it all together
>    use bytes;
>    return join("",$marc->leader, @$directory, "\x1E", @$fields, "\x1D");
> }
> use warnings;
> 1;
> __END__
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.