Hi James, please reply to all recipients.
On Fri, 8 Apr 2016 10:47:57 +0100 James Kerwin <jkerwin2...@gmail.com> wrote: > Good morning/afternoon all (depending on where you are), > > This should be a quick one: > > When creating files in a perl script is there a way to limit the size of > the file created? If somebody could give me a term to search for that > should be enough. > > I have googled this but I can't find an answer. I'm probably not using the > right search terms because this seems very do-able and I'm surprised to > have not found anything. > > My situation is as follows: > > I perform some text manipulation on files that are 30 MB in size. > The newly formatted files get pushed to another script that can only handle > files of 5MB maximum. > > So I would like to be able to limit the file size and start a new one when > it reaches (or comes close to) this limit. This would allow me to automate > it rather than having to manually break the big files up before continuing. > You can tell the current position in the file using http://perldoc.perl.org/functions/tell.html and write some logic to handle it. There's also http://perldoc.perl.org/functions/truncate.html . One option would be to use a custom file handle (see perldoc perltie) but that may be much slower than implementing it in a higher-level. Hope it helps. Regards, Shlomi > Thanks! > James. -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/