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

recsep => "\r\n"
and whilst that read the file, the entire contents were put in $file[0] making it unusable

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


In reply to Tie::File separator not supported by pilsdumps

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.