Search Question

Discussion in 'Perl Misc' started by Reinhard Glauber, Jan 17, 2006.

  1. 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:

    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
    Reinhard Glauber, Jan 17, 2006
    #1
    1. Advertising

  2. Reinhard Glauber

    Dr.Ruud Guest

    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."
    Dr.Ruud, Jan 17, 2006
    #2
    1. Advertising

  3. 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
    Gunnar Hjalmarsson, Jan 17, 2006
    #3
  4. "Dr.Ruud" <> schrieb im Newsbeitrag news:...

    > 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)
    Reinhard Glauber, Jan 17, 2006
    #4
  5. 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
    Gunnar Hjalmarsson, Jan 17, 2006
    #5
  6. Reinhard Glauber

    Matt Garrish Guest

    "Reinhard Glauber" <> wrote in message
    news:43cd0e28$0$20778$-online.net...
    >
    > "Dr.Ruud" <> schrieb im Newsbeitrag
    > news:...
    >> 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
    Matt Garrish, Jan 17, 2006
    #6
  7. Reinhard Glauber

    Dr.Ruud Guest

    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."
    Dr.Ruud, Jan 17, 2006
    #7

  8. > >
    > > 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 ;-))
    Reinhard Glauber, Jan 17, 2006
    #8
  9. Reinhard Glauber

    John Bokma Guest

    "Reinhard Glauber" <> 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 :)
    John Bokma, Jan 17, 2006
    #9
  10. Reinhard Glauber <> 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
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 18, 2006
    #10
  11. On 2006-01-18, Tad McClellan <> wrote:
    >
    > dot (.) matches any character.


    Um... not unless you're following damian's advice to use the /s modifier
    at all times. Under normal circumstances it matches any character
    *except a newline*.

    dha

    --
    David H. Adler - <> - http://www.panix.com/~dha/
    "What is this Japanese preoccupation with the name Ken???" - Tom Servo
    David H. Adler, Jan 18, 2006
    #11
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=

    Google search result like site search!! How?

    =?Utf-8?B?TGFrc2htaSBOYXJheWFuYW4uUg==?=, May 5, 2005, in forum: ASP .Net
    Replies:
    3
    Views:
    671
    Lucas Tam
    May 6, 2005
  2. Andy
    Replies:
    1
    Views:
    357
    Jack Klein
    Nov 25, 2003
  3. Anand Pillai

    String search vs regexp search

    Anand Pillai, Oct 12, 2003, in forum: Python
    Replies:
    10
    Views:
    593
    Anand Pillai
    Oct 15, 2003
  4. mason66
    Replies:
    0
    Views:
    421
    mason66
    Jul 27, 2006
  5. Abby Lee
    Replies:
    5
    Views:
    398
    Abby Lee
    Aug 2, 2004
Loading...

Share This Page