How to Delete File Contents

Discussion in 'Perl Misc' started by newzguy, Aug 7, 2004.

  1. newzguy

    newzguy Guest

    How do I delete a file's content? I don't want it to
    append, I want the contents overwritten, how do I
    do it? What I have is:

    # Append the fetched data to the local file.

    open out, ">>$localfile";
    print out $result->content;
    close out;

    Does the >> have something to do with appending?


    thanks
    newzguy, Aug 7, 2004
    #1
    1. Advertising

  2. (newzguy) wrote in news:6d7814d4.0408061938.3856e8a4
    @posting.google.com:

    > How do I delete a file's content? I don't want it to
    > append, I want the contents overwritten, how do I
    > do it? What I have is:
    >
    > # Append the fetched data to the local file.
    >
    > open out, ">>$localfile";


    open my $out, '>', $localfile or die "Cannot open $localfile: $!";

    > print out $result->content;
    > close out;
    >
    > Does the >> have something to do with appending?


    perldoc -f open
    A. Sinan Unur, Aug 7, 2004
    #2
    1. Advertising

  3. (newzguy) writes:

    > How do I delete a file's content? I don't want it to
    > append, I want the contents overwritten, how do I
    > do it? What I have is:
    >
    > # Append the fetched data to the local file.
    >
    > open out, ">>$localfile";


    Instead use

    open out, ">$localfile";

    See the documentation for open for more information.

    ----ScottG.
    Scott W Gifford, Aug 7, 2004
    #3
  4. newzguy wrote:
    > How do I delete a file's content?


    Many different ways.
    - you could delete the file and then recreate it; however coming to think of
    it this would create new file although with the same file name.
    - you could open the file for writing and immediately close it again
    - ...

    > I don't want it to
    > append, I want the contents overwritten, how do I
    > do it? What I have is:
    >
    > # Append the fetched data to the local file.


    You don't want to append but you append?
    Mind to explain?

    > open out, ">>$localfile";


    Ok, you code comforms with the comment, but both of those conflict with your
    spec.

    > print out $result->content;
    > close out;
    >
    > Does the >> have something to do with appending?


    What happened when you read the documentation for the open() function?

    jue
    Jürgen Exner, Aug 7, 2004
    #4
    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. Poppy

    delete contents of text file

    Poppy, Feb 11, 2004, in forum: ASP .Net
    Replies:
    6
    Views:
    7,353
    Poppy
    Feb 11, 2004
  2. Don Adams
    Replies:
    1
    Views:
    579
    Martin Honnen
    Mar 5, 2004
  3. jen
    Replies:
    0
    Views:
    708
  4. Kamarulnizam Rahim
    Replies:
    4
    Views:
    203
    Robert Klemme
    Jan 28, 2011
  5. Replies:
    0
    Views:
    177
Loading...

Share This Page