For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > April 2004 > Matching pattern in multiple lines









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Matching pattern in multiple lines
Prabu

2004-04-07, 10:32 am

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



Jayakumar Rajagopal

2004-04-07, 11:35 am



-----Original Message-----
From: news [mailto:news@sea.gmane.org]On Behalf Of prabu
Sent: Wednesday, April 07, 2004 9:35 AM
To: beginners@perl.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=3D"text in 1st line "/n" text in secondline";
$replace=3D"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 :
$*=3D1;
Don't use \n, but you can use '^'to match just after '\n'

thanks,
Jay


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


Rob Dixon

2004-04-07, 11:35 am

Prabu wrote:
>
> 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?


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 analysis may be wrong, but I know it can
be difficult to publish live data.

Rob


Prabu

2004-04-07, 11:35 am



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" <rob@dixon.port995.com> wrote in message
news:20040407135521.99803.qmail@onion.perl.org...
> Prabu wrote:
decalring[color=darkred]
command?[color=darkred]
>
> 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 analysis may be wrong, but I know it can
> be difficult to publish live data.
>
> Rob
>
>
>
> --
> To unsubscribe, e-mail: beginners-unsubscribe@perl.org
> For additional commands, e-mail: beginners-help@perl.org
> <http://learn.perl.org/> <http://learn.perl.org/first-response>
>
>
>



---
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



Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com