I am new to both perl and this forum. Please forgive any possible etiquette issues as I do not intend to be rude. I'm also nowhere near solid with programming languages but am working toward that.

My goal is to create a perl script that will write ZEROS to a text file until the file is around 2GB in size. I have the following code that works for a single file:

use strict; use warnings; my $filename = 'recipe.txt'; open(my $fh, '>', $filename) or die "Could not open file 'recipe.txt'" +; print $fh "0" x 2147483648; close $fh; print "done\n";

The thing is, I need it to then create a new textfile, append a 7-digit number to the name (to account for large storage volumes), and also fill that with zeros as with the first text file.

I can do the math as needed for each drive/volume in order to know how many files will need to be created. I could use help with the perl code to create text files, then write to them until the amount of space has been overwritten by these next text files.

My goal is to overwrite a hard drive after a client project completes in order to secure their privacy. Sure, I could do this via a linux command prompt, but I often have some idle/under-used Windows machines, so I was hoping to use perl to accomplish this. I rarely have an extra linux box available at present. Plus, if I can get this working via perl, then I should be able to utilize it on any Unix/Linux machines I get down the line, even if a few tweaks are needed. Plus, I want to learn Perl and find ways to use it to my advantage.

I suspect that this will involve variables for the name creation (at least the incremental numbering). If I could tell it how many files to create (edit the script before running) that would work I think.

Thanks in advance for any assistance you can provide.


In reply to Create text files recursively and write ZEROS within them all - data overwriting purposes by panicbuttonsec

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.