Professional Web Applications Themes

Matching pattern in multiple lines - PERL Beginners

Hello All, Thanks for the useful informations given on my previous queries.Now I have another one query. Please help me. In pattern matching,I want to match a pattern in multiple line.How to do this?. For example,in a file,the pattern is present in 2 lines, Here my doubts are: 1.Whether need to use "/n" to distinguish between 2 lines,when decalring them? Or anyother operator needed to be used?. (ie) $pattern="text in 1st line "/n" text in secondline"; $replace="some text"; 2. Whether to specify any options in the "s/$pattern/$replace/g" command? Thanks inadvance, Prabu. --- Outgoing mail is certified Virus Free. Checked by ...

  1. #1

    Default Matching pattern in multiple lines

    Hello All,
    Thanks for the useful informations given on my previous queries.Now I
    have another one query.
    Please help me.
    In pattern matching,I want to match a pattern in multiple line.How to do
    this?.
    For example,in a file,the pattern is present in 2 lines,
    Here my doubts are:
    1.Whether need to use "/n" to distinguish between 2 lines,when decalring
    them?
    Or anyother operator needed to be used?.
    (ie) $pattern="text in 1st line "/n" text in secondline";
    $replace="some text";
    2. Whether to specify any options in the "s/$pattern/$replace/g" command?

    Thanks inadvance,
    Prabu.


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.620 / Virus Database: 399 - Release Date: 3/11/2004



    Prabu Guest

  2. #2

    Default RE: Matching pattern in multiple lines



    -----Original Message-----
    From: news [mailto:gmane.org]On Behalf Of prabu
    Sent: Wednesday, April 07, 2004 9:35 AM
    To: org
    Subject: Matching pattern in multiple lines


    Hello All,
    Thanks for the useful informations given on my previous queries.Now I
    have another one query.
    Please help me.
    In pattern matching,I want to match a pattern in multiple line.How to do
    this?.
    For example,in a file,the pattern is present in 2 lines,
    Here my doubts are:
    1.Whether need to use "/n" to distinguish between 2 lines,when decalring
    them?
    Or anyother operator needed to be used?.
    (ie) $pattern="text in 1st line "/n" text in secondline";
    $replace="some text";
    2. Whether to specify any options in the "s/$pattern/$replace/g" command?

    Thanks inadvance,
    Prabu.


    It is not "/n" but "\n"

    USE :
    $*=1;
    Don't use \n, but you can use '^'to match just after '\n'

    thanks,
    Jay


    --
    To unsubscribe, e-mail: org
    For additional commands, e-mail: org
    <http://learn.perl.org/> <http://learn.perl.org/first-response>


    Jayakumar Guest

  3. #3

    Default Re: Matching pattern in multiple lines

    Prabu wrote: 

    Hi Prabu.

    Can you explain better what it is you need to do? Reading multi-line
    records from a file is a problem in itself; have you got that far?

    A (real) example of your data would help a lot. Try not to show us an
    invented example, as your ysis may be wrong, but I know it can
    be difficult to publish live data.

    Rob


    Rob Guest

  4. #4

    Default Re: Matching pattern in multiple lines



    Thanks for the reply,
    the want to replace the $pattern in a .html file,with a $repalce

    the $pattern="<td align=right valign=top width=10><img border=0 height=10
    src="http://ramesh.com/images/corner_2.gif"
    width=10></td>
    $replace="a javascript variable""/images/corner_2.gif" width=10></td>"

    my repalce is donw with the command inside file operation;

    while (<IN>){
    s/\Q$pattern\E/$own/m;

    How to do this?
    Prabu.





    "Rob Dixon" <port995.com> wrote in message
    news:perl.org... [/ref]
    decalring [/ref]
    command? 


    ---
    Outgoing mail is certified Virus Free.
    Checked by AVG anti-virus system (http://www.grisoft.com).
    Version: 6.0.620 / Virus Database: 399 - Release Date: 3/11/2004



    Prabu Guest

Similar Threads

  1. pattern matching
    By Tad McClellan in forum PERL Beginners
    Replies: 30
    Last Post: June 23rd, 07:42 PM
  2. Help with pattern matching
    By A in forum PERL Beginners
    Replies: 2
    Last Post: April 4th, 08:52 PM
  3. Help; Pattern Matching
    By MJS in forum PERL Miscellaneous
    Replies: 6
    Last Post: September 27th, 01:22 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139