Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Answer: How do I pre-extend a file to a specified size

by abhishek_akj (Initiate)
on Aug 26, 2009 at 10:24 UTC ( #791303=categorized answer: print w/replies, xml ) Need Help??

Q&A > files > How do I pre-extend a file to a specified size - Answer contributed by abhishek_akj

open FILEHANDLE, " +< filename" or die "Unable to open: $! \n"; truncate FILEHANDLE, $desired_length or print "Unable to truncate: $ +! \n";
truncate just sets the filesize of the file opened by handle to whatever you specify; you can use it to remove characters from file as well as increase the filesize.

Replies are listed 'Best First'.
Re: Answer: How do I pre-extend a file to a specified size
by Mr. Muskrat (Canon) on Aug 26, 2009 at 17:29 UTC

    Actually, setting the length greater than the actual file size is undefined behavior.

Log In?
Username:
Password:

What's my password?
Create A New User
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (9)
As of 2020-04-03 18:05 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    The most amusing oxymoron is:
















    Results (30 votes). Check out past polls.

    Notices?