Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re^2: Deleting all the data after a specific position in a text file.

by pankaj_it09 (Scribe)
on Nov 18, 2011 at 13:06 UTC ( [id://938809]=note: print w/replies, xml ) Need Help??


in reply to Re: Deleting all the data after a specific position in a text file.
in thread Deleting all the data after a specific position in a text file.

The problem is that we have to calculate the file size and then subtract to get the value of the truncate LENGTH.
  • Comment on Re^2: Deleting all the data after a specific position in a text file.

Replies are listed 'Best First'.
Re^3: Deleting all the data after a specific position in a text file.
by choroba (Cardinal) on Nov 18, 2011 at 13:29 UTC
    You does not have to. If you mean size in bytes rather than characters, this can work:
    seek $FH,-100, 1 or die $!; truncate "file", tell $FH or die $!; # Cannot use $FH in truncate, it' +s closed
Re^3: Deleting all the data after a specific position in a text file.
by BrowserUk (Patriarch) on Nov 18, 2011 at 19:27 UTC
    The problem is that we have to calculate the file size and then subtract to get the value of the truncate LENGTH.

    Is that soo difficult?

    Maybe you're making the same mistake as the other posters and thinking you need to open the file first and seek around in it? You don't:

    c:\test>dir junk.dat 18/11/2011 19:23 893 junk.dat c:\test>perl -E"$f=pop; $s=-s($f); truncate $f, $s-40 or die $!" junk. +dat c:\test>dir junk.dat 18/11/2011 19:24 853 junk.dat

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://938809]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (1)
As of 2024-04-25 04:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found