Welcome to Dream.In.Code
Getting Help is Easy!

Join 136,519 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,769 people online right now. Registration is fast and FREE... Join Now!




Finding A Particular Line In a Text File

 
Reply to this topicStart new topic

Finding A Particular Line In a Text File

homemade-jam
10 Aug, 2008 - 07:42 AM
Post #1

eeeAddict
Group Icon

Joined: 17 Mar, 2008
Posts: 1,066



Thanked: 1 times
Dream Kudos: 25
My Contributions
I've written a prog that automatically logs into my outlook web access account, that's no problem..however, I then get a dump of the contents of the page containing my emails. How would I be able to sift through the text file until it says xxx.EML and then get all the name of the email, which will begin with /Inbox/

So, just to clarify, the text I'm looking for is... Inbox/Name%20of%20email.EML
then the found emails need to be spat onto the screen.


Heres my stab in the dark..

if ($page =~ "/Inbox/*.EML") { # The char stream of the page is stored in $page
print 'match';
}

How would I get it to track back from the EML to the beginning of the /Inbox/?
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Finding A Particular Line In A Text File
10 Aug, 2008 - 12:33 PM
Post #2

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
Did you search for any modules already written? I am sure there must be. Even if you don't want to use the module you can look in its source code and reverse engineer the code.
User is offlineProfile CardPM
+Quote Post

homemade-jam
RE: Finding A Particular Line In A Text File
11 Aug, 2008 - 04:58 AM
Post #3

eeeAddict
Group Icon

Joined: 17 Mar, 2008
Posts: 1,066



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(KevinADC @ 10 Aug, 2008 - 01:33 PM) *

Did you search for any modules already written? I am sure there must be. Even if you don't want to use the module you can look in its source code and reverse engineer the code.

Are there not any built in commands, designed for searching thru files?

This post has been edited by homemade-jam: 11 Aug, 2008 - 04:59 AM
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Finding A Particular Line In A Text File
11 Aug, 2008 - 09:35 AM
Post #4

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
QUOTE(homemade-jam @ 11 Aug, 2008 - 05:58 AM) *

QUOTE(KevinADC @ 10 Aug, 2008 - 01:33 PM) *

Did you search for any modules already written? I am sure there must be. Even if you don't want to use the module you can look in its source code and reverse engineer the code.

Are there not any built in commands, designed for searching thru files?


There are a number of ways to search through files with perl. grep() or open() are two builtin functions to get access to the data in a file.
User is offlineProfile CardPM
+Quote Post

homemade-jam
RE: Finding A Particular Line In A Text File
11 Aug, 2008 - 12:48 PM
Post #5

eeeAddict
Group Icon

Joined: 17 Mar, 2008
Posts: 1,066



Thanked: 1 times
Dream Kudos: 25
My Contributions
I solved my problem...this just searches for an instance of the graphic of an unread message..
I used Stream::Reader
CODE

my @substrings = (
'icon-msg-unread.gif'
);
my $handler;
open( $handler,'<','school.txt' ) or die;
my $stream = Stream::Reader->new( $handler );
my $result = $stream->readto(\@substrings, {Mode => 'E'}); #This mode returns false apparently
$emails = 1;

if( $result ) {
print ("You have new mail.'$stream->{Match}'\n"); $emails++;
} elsif( $stream->{Error} ) {
  die "Fatal error during reading file!\n";
} else {
  print "No new messages.\n";
}

User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Finding A Particular Line In A Text File
11 Aug, 2008 - 03:42 PM
Post #6

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
Very good.
User is offlineProfile CardPM
+Quote Post

homemade-jam
RE: Finding A Particular Line In A Text File
11 Aug, 2008 - 03:44 PM
Post #7

eeeAddict
Group Icon

Joined: 17 Mar, 2008
Posts: 1,066



Thanked: 1 times
Dream Kudos: 25
My Contributions
QUOTE(KevinADC @ 11 Aug, 2008 - 04:42 PM) *

Very good.

Really? My second day of perling..
User is offlineProfile CardPM
+Quote Post

KevinADC
RE: Finding A Particular Line In A Text File
11 Aug, 2008 - 10:38 PM
Post #8

D.I.C Head
Group Icon

Joined: 23 Jan, 2007
Posts: 216



Thanked: 3 times
Dream Kudos: 50
My Contributions
OK, fess up, where did you get the code from? wink2.gif


User is offlineProfile CardPM
+Quote Post

homemade-jam
RE: Finding A Particular Line In A Text File
12 Aug, 2008 - 01:01 AM
Post #9

eeeAddict
Group Icon

Joined: 17 Mar, 2008
Posts: 1,066



Thanked: 1 times
Dream Kudos: 25
My Contributions
haha, well now you ask I have "adapted" one of the examples that came with Stream::Reader, but most of it was my own hard coding biggrin.gif
Still trying to get it to recognise multiple occurences of the string tho...
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 12/2/08 09:23PM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month