>>>>> "O" == Owen  <rc...@pcug.org.au> writes:

  O> This will generate 10000 files in less than a second. They are 0 size,
  O> so just write something into them if you don't wont zero sized files

might as well clean this up.

  O> #!/usr/bin/perl
  O> use strict;
  O> my $file = "/some/where/writeable/a1";

  O> my $j    = 0;

  O> for ( my $i = 1 ; $i < 10000 ; $i++ ) {

classic c loop. don't do c loops unless you must. they are not very
perlish. perl loops are cleaner and faster:

        foreach my $i ( 1 .. 10000 ) {

  O>     my $dts = $j++;

why don't you just use $j? or even $i?? change the loop and use $dts.

        foreach my $dts ( 0 .. 99999 ) {

  O>     open( my $FH, ">", "$file$dts" ) or die "cant open file$dts!";
  O>     close $FH;

and using File::Slurp cleans that up too:

use File::Slurp ;
        write_file "$file$dts", '' ;

or even:

        write_file "$file$_", '' for 0 .. 99999 ;

that allows for data instead of '' as well.

uri

-- 
Uri Guttman  ------  u...@stemsystems.com  --------  http://www.sysarch.com --
-----  Perl Code Review , Architecture, Development, Training, Support ------
---------  Gourmet Hot Cocoa Mix  ----  http://bestfriendscocoa.com ---------

-- 
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to