aidan has asked for the wisdom of the Perl Monks concerning the following question:

Perhaps I'm just being stupid...
use strict; use Tie::File; use Date::Manip; use Fcntl; tie my @log, 'Tie::File', 'logfile', mode => O_RDONLY or die "Unable t +o open file"; for (@log) { my $t = "$_"; if ($t =~ /time: (.* 2008)/) { my $xxx = ParseDate($1); } } untie @log;
When I run it I get
Couldn't write record: Bad file descriptor at /usr/lib/perl5/5.8.5/Tie/File.pm line 907, <$fh> line 44063.

I think this only happens when something tries to write to a Tied file when it can't be written to.

And it's the my $xxx... line that causes it. How is that possible?

Thanks for any pointers!

Replies are listed 'Best First'.
Re: Is this a bug with Date::Manip?
by almut (Canon) on Nov 11, 2008 at 15:02 UTC

    The problem has nothing in particular to do with Date::Manip. It's caused by something (from within ParseDate()) trying to modify the global $_, which is aliased to your tied log (something like $_ = "foo"; instead of the my $xxx = ParseDate($1); would have the same effect).   Rewrite your for-loop as

    for my $t (@log) { # ... }

    and everything should be fine.

      Thanks almut,
      So I was being stupid!