Perl Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPerl Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old June 7th, 2001, 03:14 AM
astrix astrix is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2000
Location: Chicago, IL USA
Posts: 48 astrix User rank is Corporal (100 - 500 Reputation Level)astrix User rank is Corporal (100 - 500 Reputation Level)astrix User rank is Corporal (100 - 500 Reputation Level)astrix User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 12
Send a message via ICQ to astrix
Talking file parsing

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!

Reply With Quote
  #2  
Old June 7th, 2001, 06:17 AM
MattWilliams MattWilliams is offline
hmmmm...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: UK
Posts: 37 MattWilliams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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.

Reply With Quote
  #3  
Old June 7th, 2001, 03:24 PM
mullaney mullaney is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: May 2001
Posts: 0 mullaney User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
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

Reply With Quote
  #4  
Old June 8th, 2001, 02:45 AM
MattWilliams MattWilliams is offline
hmmmm...
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Mar 2001
Location: UK
Posts: 37 MattWilliams User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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;
}

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > file parsing


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
Stay green...Green IT