Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Re: get the rest of the text

by Punitha (Priest)
on Feb 27, 2008 at 09:59 UTC ( #670568=note: print w/ replies, xml ) Need Help??


in reply to get the rest of the text

Hi steph_bow,

You can get the previous text from the matching string by using '$`' and the following text by using '$'' like,

#!/usr/bin/perl use strict; use warnings; my $element = "coucou"; open (INFILE, "<EXEMPLE.txt"); while (my $line = <INFILE>){ if ($line =~ /$element/){ my $pre=$`;###to get the previous text from the matching t +ext my $post=$';###to get the following text from the matching + text print "PREVIOUS:$pre\nFOLLOWING:$post\n"; } } close INFILE;

Punitha


Comment on Re: get the rest of the text
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://670568]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (7)
As of 2015-07-04 14:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (60 votes), past polls