in reply to Edit html files in directory
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 );
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Edit html files in directory
by hilitai (Monk) on Aug 22, 2007 at 14:15 UTC | |
|
Re^2: Edit html files in directory
by Anonymous Monk on Aug 22, 2007 at 14:32 UTC | |
by clinton (Priest) on Aug 22, 2007 at 14:53 UTC | |
by Anonymous Monk on Aug 22, 2007 at 14:37 UTC |