I looked at your code, and didn't see anything wrong, so I tried your 
program with my own test directories...and it worked fine for me.  What 
exactly seems to be the problem?

One thing I noticed (but shouldn't be causing your problem) was that you 
did an unlink on miami-$Name but not on miami.$Name...wasn't sure if it 
was intentional to only unlink one, or if you wanted to unlink both.


Jessica

On Mon, 29 Apr 2002, Nick Selby wrote:

> Hi, all,
> I am a total newbie and I have a script here that's behaving strangely. Its 
> purpose is to go into a directory, take the file names, search them for a 
> string and replace it (in this case removing a prefix from the file name) , 
> write the new files to disk, delete the old ones and that's the ball game.
> 
> Sadly, it seems to work in an unpredictable manner. Can anyone have a look 
> and see if it's some totally stupid thing I did?
> 
> Thanks in advance.,
> 
> Nick
> 
> #Open the directory and name the list of file names
> opendir(DIR, '/home/bart/dir/backup') or die "Doh\!\n";
> @Names = readdir(DIR); #Hopefully gives me the names in a list form
> closedir(DIR);  #close it
> 
> # foreach file in the directory.
> foreach $Name (@Names) {
> 
> #leave out . and ..
> if ( ($Name eq '.') or ($Name eq '..') ) { next; }
> 
> #get the remaining content
> open (FH, "/home/bart/dir/backup/$Name")  or die "Fail to open $Name for 
> writing: $!";
> $content = join("",<FH>);
> close FH;
> 
> # make new file name
> $Name =~ s/miami-//;
> $Name =~ s/miami.//;
> 
> #...do whatever with content here...
> 
> # open a new file
> open (FH, ">/home/bart/dir/backup/$Name") or die "Fail to open $Name for 
> writing: $!";
> print FH $content;
> close FH;
> 
> # ensure FTP user can manipulate the new file
> chmod (0777, "/home/bart/dir/backup/$Name");
> unlink "/home/bart/dir/backup/miami-$Name";
> } 
> 
> _______________________________________________
> Perl-Unix-Users mailing list
> [EMAIL PROTECTED]
> To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs
> 

-- 

_______________________________________________
Perl-Unix-Users mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

Reply via email to