Problems at writing multiple files

Discussion in 'Perl Misc' started by vladimir.giron@gmail.com, Oct 5, 2006.

  1. Guest

    I have a problem at writing multiple files. I have this code where I
    write several XML files (the number of files it's dynamic). I use a
    loop and in Linux works fine but the problem is Windows.

    For example lets say that I want to write a long essay into 1 file,
    Windows and Linux do it as it should be, the problem comes when I want
    to write that same essay (divided into 5 parts) in 5 files. Linux works
    fine but windows skips the first part (the first file is not written)
    and the remaining parts are written well.. if I want to write the essay
    into 10 files, the first three are not written and as the number of
    files grows so does the number of files not written.

    Does anyone knows why could this be? Next is the part of the code where
    I write into the files.


    local *FILE_X;
    eval {
    if(substr($filename, length($filename) - 4) eq '.txt')
    { #this does nothing yet }
    else { my $success = open ::FILE, "> $filename";
    unless($success) { $output->Error("Can not open file:
    $filename");
    return $False; }
    print ::FILE $FILE_HEADER;
    foreach my $line (@{$self->{_set}})
    { $line->WriteXML(*FILE_X{IO}); }
    print ::FILE $FILE_FOOTER;
    close ::FILE; } };
    if($@) { $output->Fatal("Couldn't write out to file: $filename"); }
    chmod(0644, $filename);


    sub WriteXML {
    my($self, $file) = @_;

    if(!$self->{loc}){
    return;
    }
    my $out = $XML_PREFIX;

    foreach my $attribute (@__slots__){
    my $value = $self->{$attribute};
    if($value) {
    if(Encode::is_utf8($value)) {
    $value = $encoder->NarrowText($value, undef);
    }

    #Escape characters
    $value =~ s/&/&/g;
    $value =~ s/'/'/g;
    $value =~ s/"/"/g;
    $value =~ s/</&lt;/g;
    $value =~ s/>/&gt;/g;
    $out .= " <$attribute>$value</$attribute>\n";
    }
    }
    $out = $out . $XML_SUFFIX;
    if(0) {
    #nothing yet
    }
    else {
    print ::FILE $out;
    }
    }
    , Oct 5, 2006
    #1
    1. Advertising

  2. wrote:
    > I have a problem at writing multiple files. I have this code where I
    > write several XML files (the number of files it's dynamic). I use a
    > loop and in Linux works fine but the problem is Windows.
    >
    > For example lets say that I want to write a long essay into 1 file,
    > Windows and Linux do it as it should be, the problem comes when I want
    > to write that same essay (divided into 5 parts) in 5 files. Linux works
    > fine but windows skips the first part (the first file is not written)
    > and the remaining parts are written well.. if I want to write the essay
    > into 10 files, the first three are not written and as the number of
    > files grows so does the number of files not written.


    Are the files created but have no content?

    > Does anyone knows why could this be? Next is the part of the code where
    > I write into the files.


    Is possible you need to set binmode, but would depend on your data.

    Mark
    Mark Clements, Oct 5, 2006
    #2
    1. Advertising

  3. Guest

    Mark Clements wrote:
    > wrote:
    > > I have a problem at writing multiple files. I have this code where I
    > > write several XML files (the number of files it's dynamic). I use a
    > > loop and in Linux works fine but the problem is Windows.
    > >
    > > For example lets say that I want to write a long essay into 1 file,
    > > Windows and Linux do it as it should be, the problem comes when I want
    > > to write that same essay (divided into 5 parts) in 5 files. Linux works
    > > fine but windows skips the first part (the first file is not written)
    > > and the remaining parts are written well.. if I want to write the essay
    > > into 10 files, the first three are not written and as the number of
    > > files grows so does the number of files not written.

    >
    > Are the files created but have no content?
    >
    > > Does anyone knows why could this be? Next is the part of the code where
    > > I write into the files.

    >
    > Is possible you need to set binmode, but would depend on your data.
    >
    > Mark


    I found the problem! After a few weeks with the bug I found what it
    was.. I was using a relative path so while the files were been read and
    written they weren't stored into the folder I told it but into the
    folder of the essay. When just one file was written the file was stored
    into the right place but with several just the last ones where stored
    into the place I told the program. Weird!

    Mark, thanks for your input.
    , Oct 6, 2006
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. HNguyen
    Replies:
    4
    Views:
    2,371
    HNguyen
    Dec 21, 2004
  2. Replies:
    9
    Views:
    5,575
    Chris Uppal
    Mar 22, 2006
  3. PA
    Replies:
    0
    Views:
    386
  4. Replies:
    4
    Views:
    929
    M.E.Farmer
    Feb 13, 2005
  5. Shunichi Wakabayashi

    Writing multiple files with with-context

    Shunichi Wakabayashi, May 23, 2011, in forum: Python
    Replies:
    1
    Views:
    281
    Ian Kelly
    May 23, 2011
Loading...

Share This Page