in reply to Massive File Editing
Example:
Then for your example you would test to see if the file extension was .shtml and if it was open the file and read it, whether to read in the file as a glob or line really depends on two issues;# Try to match the expected input line format (from "ls" output) # if ("$_" =~ /^\-.+ ([0-9]+) ([A-Z|a-z]+ [ ]?[0-9]+ [ ]?[:|0-9]+) (.+) +$/) { # Set some defaults to avoid potentially problematic missing field +s # $file1 = "FULLNAME"; $file2 = "BASENAME"; $fext = "NO EXTENSION"; # Set file size, date and compelte filename variables $fsize =$1; $date = $2; $file1 = $3; if ("$file1" =~/^([\.]?.+)\.(.+))$/) { $file2 = $1; $fext = $2; }
1) How many times do you plan to run this, let's be honest if your only going to run this once you don't need a perfectly efficient piece of code. even though I hate to admit that.
2) How many files and the size of the files you'll be reading in.
Then as you hit the line you could either do a s// or just replace the contents of the substring. I like to cheat with a sanity test since I substitute operations seem to always do bad things to me data.
then the file open operator should be pretty straight foward (no more directory recursion woo!), if you have some problems with the output of the ls statement you may have to embedded a directory. Other than that it should be pretty straight foward. I had to write this to deal with a terrabyte file system in a lawsuit, so my solution may require more work then you are willing to deal with.if ($_ =~ /<a href="main.php?page/) { s/main.php?page=/main.php/?id=/g }
Dave -- Saving the world one node at a time
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Massive File Editing
by Aristotle (Chancellor) on Dec 16, 2002 at 19:14 UTC | |
by Zapawork (Scribe) on Dec 16, 2002 at 19:28 UTC | |
by Aristotle (Chancellor) on Dec 16, 2002 at 19:56 UTC |