|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
hey guys, i've gotta search through about 5000 HTML files and pull out several strings of text from each file then write those strings to one central file. could anyone make any suggestions before i get started on how i might make this project easier? It seems pretty difficult since i'm rather new to perl. Please help!
|
|
#2
|
|||
|
|||
|
its a quick write but should work, i have built the basics but you will have to figure out yourself how to recuse down the directories as im not going to do everything.
|
|
#3
|
|||
|
|||
|
What pattern(s) are you looking for? Is it a single word? A specific format? Are all the files locating in a single directory or parent directory? Are there files which will need to be excluded?
The good news is that this most likely will be a very short script. We just need a bit more info. Bob |
|
#4
|
|||
|
|||
|
sorry looks like the attachment didnt go through so heres the code:
#!/usr/bin/perl -w callTheBall(); sub callTheBall { my $directory = getDirectory(); # You can write this to get current dir opendir (DIR, $directory) or die "Can't opendir $Directory: $!"; while (defined($file=readdir(DIR)) ) { my $tempFile = readFile($directory,$file); $tempFile =~ s/'Data to extract'/'data to replace'/ig; open(FILE, ">$directory$file") || die "Cant open file: $file \n $!"; print FILE $tempFile; close FILE; } closedir DIR; } sub readFile { my $file = join("",@_); open(FILE, $file) || die "Cant open file: $file \n $!"; my $temp = $/; undef $/; my $data = <FILE>; $/ = $temp; close FILE; return $data; } |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Perl Programming > file parsing |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|