[SMPETERS - Mon May 2 09:34:44 2005]:
Show quoted text> I have an idea for allowing filehandles to be passed as parameters to
> the new() for Chess::PGN::Parse. The issue I have is that I have a
> few very large PGN files that I access regularly. Because of their
> size, I usually keep them gzipped. If new() can be modified to
> accept filehandles, I could pass in a PerlIO::gzip filehandle that
> would read and process the gzipped PGN files without having to
> gunzip them prior to processing. I'm hoping to have a patch
> available shortly to handle this.
Below is my patch to accept filehandles as an argument to new(). It
also adds a ';' to a line in _init() that my Perl had troubles with when
I had problems elsewhere. I changed the version for myself to
distinguish versions on my system. An example of how the changed new
works, looks like this:
#!/usr/bin/perl -w
use strict;
use Chess::PGN::Parse;
my $pgnfile = "games.pgn.gz";
my $fh;
open $fh, "<:gzip", $pgnfile;
my $pgn = new Chess::PGN::Parse $fh
or die "can't open $pgnfile\n";
while ($pgn->read_game()) {
...
}
Enjoy!
--- Chess-PGN-Parse-0.18/Parse.pm 2004-05-25 02:09:02.000000000 -0500
+++ Chess-PGN-Parse-filehandle/Parse.pm 2005-05-02 10:20:40.000000000 -0500
@@ -36,7 +36,7 @@
our @EXPORT = qw(shrink_epd expand_epd STR NAG);
our @EXPORT_OK = qw();
-our $VERSION = '0.18'; # 25-May-2004
+our $VERSION = '0.18_01'; # 25-May-2004
=head1 NAME
@@ -218,8 +218,12 @@
my $filename = shift;
my $fh = undef;
if (defined $filename) {
- $fh = new IO::File "< $filename"
- || return undef;
+ if(ref $filename eq "GLOB") {
+ $fh = $filename;
+ } else {
+ $fh = new IO::File "< $filename"
+ || return undef;
+ }
}
else {
my $text = shift;
@@ -563,7 +567,7 @@
sub _init {
my $self = shift;
for (keys %{$self->{gamedescr}}) {
- $self->{gamedescr}{$_} = ""
+ $self->{gamedescr}{$_} = "";
}
delete $self->{gamedescr}{FirstMove}
if exists $self->{gamedescr}{FirstMove};