I think the problem that you were having was due to trying to open all the results from the directory list, including "." and ".."
The code below, should fix that and I've added a quick stab at the regex you're after.
#!/usr/bin/perl use strict; use warnings; opendir(DIR, "."); my @list = readdir(DIR); closedir(DIR); foreach my $file (@list){ #the line below makes sure you don't try to open . and .. if($file !~ /^\.+$/){ open(FILE,"$file"); my @lines = <FILE>; close FILE; # Open same file for writing, reusing STDOUT open (FILE, ">$file") or die "Can't open $file: $!\n"; # Walk through lines... foreach my $line ( @lines ) { #can just make the replacement on this line $line =~ s/(\w+_[_\w]+)\(\)/<A HREF="$1.html">$1\(\)<\/A>/; print FILE $line; } close FILE; } } closedir( DIR );
In reply to Re: Edit html files in directory
by johnlawrence
in thread Edit html files in directory
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |