actually, it was almost perfect before, it would just add teh copyright
thing a few extra times...sometimes it wouldn't do it at all. i cant' really
detect a pattern as to which files to which it is doing it extra...i get teh
infinite loop now that i'm working with the array. that code is in my last
email.
thanks for any ideas
tanya

-----Original Message-----
From: Troy Sniff [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 11:46 AM
To: [EMAIL PROTECTED]
Subject: RE: directory


It is looping because of what you said. Windows will place the modified
files at the end of the directory.  Thus when you modify the last
unmodified file, it will continue with already modified files because
they were appended to the end of the directory.

This can continue forever.

Try reading your files into an array and then working with the array.

Troy

-----Original Message-----
From: Tanya Graham [mailto:[EMAIL PROTECTED]] 
Sent: Wednesday, May 30, 2001 12:32 PM
To: 'Rubinow, Larry'; Tanya Graham; 'Troy Sniff';
[EMAIL PROTECTED]
Subject: RE: directory


it looks like it is in an infinite loop now...do my curly braces look
wrong? chomp ($dirname = <STDIN>);
opendir (DIR, $dirname)                 or die "can't open directory
$dirname: $!";
$copyright = "COPYRIGHT";
        #while ( defined ($file = readdir (DIR))){
        my @files = readdir (DIR);
        foreach my $file(@files){
        while (defined $file){
        next if ($file=~/^\.+$/);
        open (SOURCE, "$dirname/$file") or die "can't open original file
$file ";
        open (NEW, ">$dirname/file2.txt")               or die "Can't
Create
new file";
        print  NEW "$copyright"                 or die "can't print
copyright info to new file";
        
        while (<SOURCE>){
                print NEW $_;
        }
        
        close NEW;
        close SOURCE;
        
        rename "$dirname/file2.txt", "$dirname/$file";
        
        }
        
}
thanks
tanya

-----Original Message-----
From: Rubinow, Larry [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, May 30, 2001 11:24 AM
To: 'Tanya Graham'; 'Troy Sniff';
[EMAIL PROTECTED]
Subject: RE: directory


Tanya Graham wrote:

> it is very close...sometimes it adds the copyright twice, it
> looks like it
> does that to the first and last file in the folder. any ideas 
> why? also, on

Weird.  It's possible you're actually reopening a file you've already
prepended to.  Don't know.  To ensure you're not doing this, try reading
all the file names at once, rather than one by one; then you don't have
to worry about the OS modifying the directory contents while your loop
is running.

Instead of 

        while ( defined ($file = readdir (DIR))){

try

        my @files = readdir( DIR );
        foreach my $file(@files) {
                while( defined $file ) {
                # ...

> a larger note, do you think there will be problems when i'm using this

> program to alter .c and .cpp files (among others). i'm going to have 
> to use this program to change this company's code, and i don't know if

> having file2.txt will screw things up.
> thanks
> tanya

Your code renames file2.txt in each iteration; it should be gone after
the program finishes.  In any event, I can't imagine that a .txt file is
going to confuse any make environment.

_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users
_______________________________________________
Perl-Win32-Users mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/perl-win32-users

Reply via email to