Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Perl Misc (http://www.velocityreviews.com/forums/f67-perl-misc.html)
-   -   Search Question (http://www.velocityreviews.com/forums/t896137-search-question.html)

Reinhard Glauber 01-17-2006 02:38 PM

Search Question
 

Ok, the wget problem is solved, but now I have a search Problem

I have $text which contains Text :)
If he finds "E-Mail", then he cuts the whole line and prints it.

if ($html =~ /E-Mail.*\n/)
{
print "$&\n";
}


What I want to do now is, that Perl grabs 5 lines BEFORE the occurance of E-Mail.

Perl Gmbh
Munichstreet 5
80802 Munich
Tel.: 9038429038/38420384
E-Mail: blubb@blubb.de

So Perl should cut all the 4 Lines befor E-Mail and put it into an array, or something like that.

I dont need the whole code, just some tips how to do that

THANKS



Dr.Ruud 01-17-2006 03:10 PM

Re: Search Question
 
Reinhard Glauber schreef:

> if ($html =~ /E-Mail.*\n/)
> {
> print "$&\n";
> }
>
> What I want to do now is, that Perl grabs 5 lines BEFORE the
> occurance of E-Mail.


Or 4 lines before:

print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;

--
Affijn, Ruud

"Gewoon is een tijger."

Gunnar Hjalmarsson 01-17-2006 03:29 PM

Re: Search Question
 
Reinhard Glauber wrote:
> Ok, the wget problem is solved, but now I have a search Problem
>
> I have $text which contains Text :)
> If he finds "E-Mail", then he cuts the whole line and prints it.
>
> if ($html =~ /E-Mail.*\n/)
> {
> print "$&\n";
> }


Then you solved your search problem, right?

> What I want to do now is, that Perl grabs 5 lines BEFORE the occurance of E-Mail.


Then you need to tell Perl to do that.

- Which efforts did you make to complete the task before asking for help
here?
- Where is the code showing your best shot?
- Have you read the posting guidelines for this group, as Sinan
suggested in the other thread?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Reinhard Glauber 01-17-2006 03:33 PM

Re: Search Question
 

"Dr.Ruud" <rvtol+news@isolution.nl> schrieb im Newsbeitrag news:dqj4vl.18c.1@news.isolution.nl...

> Reinhard Glauber schreef:


> > What I want to do now is, that Perl grabs 5 lines BEFORE the
> > occurance of E-Mail.

>
> Or 4 lines before:
>
> print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;



that works :) thank you

but what means (?:.*\n)

Gunnar Hjalmarsson 01-17-2006 03:57 PM

Re: Search Question
 
Reinhard Glauber wrote:
> "Dr.Ruud" schrieb:
>>Reinhard Glauber schreef:
>>>What I want to do now is, that Perl grabs 5 lines BEFORE the
>>>occurance of E-Mail.

>>
>>Or 4 lines before:
>>
>> print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;

>
> that works :) thank you
>
> but what means (?:.*\n)


Yes, how rude of you, Dr. Ruud, to not thoroughly explain every detail
of the expression you posted!!

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

Matt Garrish 01-17-2006 04:04 PM

Re: Search Question
 

"Reinhard Glauber" <kigar@gmx.net> wrote in message
news:43cd0e28$0$20778$9b4e6d93@newsread4.arcor-online.net...
>
> "Dr.Ruud" <rvtol+news@isolution.nl> schrieb im Newsbeitrag
> news:dqj4vl.18c.1@news.isolution.nl...
>> Reinhard Glauber schreef:

>
>> > What I want to do now is, that Perl grabs 5 lines BEFORE the
>> > occurance of E-Mail.

>>
>> Or 4 lines before:
>>
>> print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;

>
>
> that works :) thank you
>
> but what means (?:.*\n)
>


You should be quite capable of looking it up in perlre under the extended
patterns section.

Matt



Dr.Ruud 01-17-2006 04:32 PM

Re: Search Question
 
Reinhard Glauber schreef:
> Dr.Ruud:
>> Reinhard Glauber:


>>> What I want to do now is, that Perl grabs 5 lines BEFORE the
>>> occurance of E-Mail.

>>
>> Or 4 lines before:
>> print $1 if $html =~ /(.*\n)(?:.*\n){3}E-Mail.*/;

>
> that works [...] but what means (?:.*\n)


This is similar: /(.*\n)(.*\n){3}E-Mail.*/
Check `perldoc perlre` for the details.

--
Affijn, Ruud

"Gewoon is een tijger."

Reinhard Glauber 01-17-2006 07:58 PM

Re: Search Question
 


> >
> > but what means (?:.*\n)

>
> Yes, how rude of you, Dr. Ruud, to not thoroughly explain every detail
> of the expression you posted!!
>
> --
> Gunnar Hjalmarsson
> Email: http://www.gunnar.cc/cgi-bin/contact.pl




sorry, I'm a Perl newbie
Is this Newsgroup just for the Elite ?
Sorry if I disturbed you ;-))

John Bokma 01-17-2006 08:01 PM

Re: Search Question
 
"Reinhard Glauber" <kigar@gmx.net> wrote:

> sorry, I'm a Perl newbie
> Is this Newsgroup just for the Elite ?


Is this newsgroup just to repeat everything that is clearly documented,
and if you're serious at learning Perl *should* learn (probably by
yourself) at some time in the very near future?


--
John Small Perl scripts: http://johnbokma.com/perl/
Perl programmer available: http://castleamber.com/
I ploink googlegroups.com :-)


Tad McClellan 01-18-2006 05:37 AM

Re: Search Question
 
Reinhard Glauber <kigar@gmx.net> wrote:
>
>> >
>> > but what means (?:.*\n)

>>
>> Yes, how rude of you, Dr. Ruud, to not thoroughly explain every detail
>> of the expression you posted!!



> Is this Newsgroup just for the Elite ?



No, but it is hoped that people would spend 10 minutes trying to
find the answer on their own before asking hundreds/thousands
of people around the world about it.

Perl's regular expressions are documented in

perldoc perlrequick
perldoc perlretut
perldoc perlre


It is also hoped that you would not ask hundreds of people to bother
explaining parts that you _do_ already understand.

Which parts do you not understand?

dot (.) matches any character.

asterisk (*) matches zero or more of the previous thing.

\n matches a newline.

(?: ) does grouping, like parenthesis, but without triggering memory.


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas


All times are GMT. The time now is 08:07 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.