in reply to How to Put a Loop in my 1st Program

Congratulations on a fine choice of programming language ;o)

A few really good habits to start with are:

#!/usr/bin/perl -w use strict;
This takes away the niceness of not having to declare variables, but makes spotting bugs waaaay faster ;)

$addthis=join("", <TEXT>);
Whoa!! Nice use of join, it makes sense now I think about it. I'd suggest using ' instead of " as " interpolates stuff, and if you don't need it use ' instead ;)
open (FILES,"files.txt") || die "Could not open file: $! \n";
I prefer: open FOO,'foo.txt' or die "$! foo.txt\n";


Maybe use a while loop or a for loop, as for loops can traverse arrays too.

for (<FILES>){ chomp; # each item of the array is placed in $_ for the scope of t +he for unless (open (D,$_)){ # no need to wrap the variable in quotes print STDERR "$!:$_\n"; # In case the failure to read one file + isn't critical next; # Skips all the other commands in the loop and goes to t +he next iteration. } my $newrecord=$addthis.join('',<D>); close(D); open (D,">$_") || die "Could not write to: $! \n"; print "$_\n"; print D $newrecord; close (D) }

Watch yourself here, DATA is a reserved word IIRC like:

#!/usr/bin/perl -w use strict; $someperl=<DATA>; __DATA__ Some data
Now $someperl should contain "Some data".

--

Brother Frankus.

¤