pilsdumps has asked for the wisdom of the Perl Monks concerning the following question:
Hi,
I'm a newbie to Perl (and convert) but have a curious problem.
I'm using Tie::File in a Windows environment and have got it working just fine in a test project using this:
tie @file, 'Tie::File', $filepath; for (@file) { print "$_\n"; } print "line2 = $file[1]";
This list the file contents and pulls out line 2 as expected. However, when I run the same code within an existing project I'm working on I get the following error:
Empty record separator not supported by Tie::File ...
The file is the same, the code is the same so it's obviously something to do with my project. Trouble is I haven't got the faintest idea what. I tried using
and whilst that read the file, the entire contents were put in $file[0] making it unusablerecsep => "\r\n"
Anyone have ideas how I can resolve this? Thanks!
Update
A bit more code below. If I run the code snippet mentioned within a sub on the module I receive the error mentioned. However, if I run it outside of the sub the code works as expected. This seems a little strange to me.
package CodeSet; use strict; use warnings; use Tie::File; use Exporter; use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); $VERSION = 1.00; @ISA = qw(Exporter recControlObject); @EXPORT = (); @EXPORT_OK = qw(); %EXPORT_TAGS = ( 'all' => [ qw() ] ); #constructor sub new { my $class = shift; my $self = { }; bless ($self, $class); return $self; } print "outside sub\n"; my $filepath = 'C:/TEMP/test extended code/test1.txt'; my @file; tie @file, 'Tie::File', $filepath; for (@file) { print "$_\n"; } print "line2 = $file[1]\n"; sub Process { my $self = shift; print "inside sub\n"; my $filepath = 'C:/TEMP/test extended code/test1.txt'; my @file; tie @file, 'Tie::File', $filepath; for (@file) { print "$_\n"; } print "line2 = $file[1]\n"; } 1;
In the snippet above, Process is called from another module like this
sub RunCodeSets { my $self = shift; for ($self->CodeSets) { $_->Process; } }
Running it gives me this output
Empty record separator not supported by Tie::File at C:/Documents and Settings/hardyr/My Documents/Development/Versioned projects/Perl/recControlMaker/LocalObjects/CodeSet.pm line 40
outside sub
line 1
line 2
line 3
line2 = line 2
inside sub
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Tie::File separator not supported
by Corion (Patriarch) on Oct 18, 2010 at 09:25 UTC | |
by pilsdumps (Initiate) on Oct 18, 2010 at 09:32 UTC |