Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
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 chilling in the Monastery: (15)
As of 2014-07-10 17:29 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    When choosing user names for websites, I prefer to use:








    Results (214 votes), past polls