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
|
---|
In Section
Seekers of Perl Wisdom