Anish Kumar K. wrote:
I want to replace a text from a file say a.txt.

a.txt contains

line1: this is line 2: a
line 3: apple


I wanted to replace to "this is an orange"..

When I see perl change.pl <FILENAME>

it shld change all the occurence of "this is a apple" to "this is an
orange". Not that this search text can be split in multilines.
Do perl have some inbulit functions to do the same.

The s/// operator (see "perldoc perlop") is a suitable tool for doing that. Since you need to search over several lines, it's probably best to slurp the file as one single string into a scalar variable:

    my $txt = do { local $/; <FILE> };

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

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




Reply via email to