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:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old March 22nd, 2000, 01:25 PM
till till is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 1999
Posts: 7 till User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I'm trying to collect data from an email account, I tried to figure out a way with PHP to access the mail file and look for the string in it, but I didn't have an idea how to do it.

I came accross perl, but my expertise isn't that great either here. Some people also told me about grep, but couldn't really explain how.

Maybe someone can tell me how I would access let's say a file called some.file and parse everything between <x> and </x> and write it to a file.

Thanks,
Till

Reply With Quote
  #2  
Old March 23rd, 2000, 05:33 PM
ryanh ryanh is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Aug 1999
Posts: 119 ryanh User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 m 41 sec
Reputation Power: 9
to open a file, just use the open function (perldoc -f open).

the easiest way to get the contents of that is to use read (perldoc -f read).

then, once you've done that, it's a matter of using regular expressions. Those are a bit more difficult to understand, but try "man perlre".

Here's an example of one that you may be able to use, haven't tested it and my skills at REs are not mastered (understatement).

# contents of file in $c
if ( $c =~ m|<x>([^</x>]*)</x>|im ) {
$d = $1;
}
# now $d has everything b/w <x> and </x>

I don't have time to look and see if '<' and '>' are special characters, but I don't think they are.

I'm sure someone will correct me if this is wrong...

good luck.

Reply With Quote
  #3  
Old April 5th, 2000, 02:27 PM
donarb donarb is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 1999
Location: Seattle
Posts: 133 donarb User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
Except you used ([^</x>]*). If the text between the tags contains an 'x', the regular expression will fail since character classes match if any character is in the class, not necessarily those in sequence.

A better way is to just use ([^<]*) which will stop when the '<' of the end tag is found.

Don

Reply With Quote
  #4  
Old April 11th, 2000, 01:54 PM
Imo Imo is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 1999
Posts: 33 Imo User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 10
don, wouldn't that miss out all <'s?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesPerl Programming > 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 1 hosted by Hostway