-3

This is my code

   use strict;
   use warnings;
   my $string=" The UNIX grep filters the lines of a file based on a regular expression.Perl's grep can filter any list of value based on any condition. This Perl code implements a basic version of the UNIX grep:  ";
   $string =~ m/grep/;
   print "$& $'\n";

This is my output:

grep can filter any list of value based on any condition. This Perl code implements a basic version of the UNIX grep:

But I want Output is

grep can filter any list of value based on any condition. This Perl code

Can Anyone help me ??

Chella
  • 43
  • 6
  • `print((split /(?=grep)/, $string)[1], "\n")` – Borodin Jan 13 '16 at 06:05
  • Thanks for your reply but I change like print((split /(?=filters)/, $string)[1], "\n"); The Output is [filters the lines of a file based on a regular expression.Perl's grep can filter any list of value based on any condition.This Perl code implements a basic version of the UNIX grep:] It cannot set end boundary value .I want print until [code] what i do – Chella Jan 13 '16 at 06:27
  • Ah okay. You want `print $string =~ /(filters.*?code)/, "\n"` – Borodin Jan 13 '16 at 06:30
  • Thanks sir I am using like this [ print((split /(?=filters)|(?=code)/, $string)[1], "\n");] . Output is [filters the lines of a file based on a regular expression.Perl's grep can filter any list of value based on any condition. This Perl ] code is not printed in this output What I do – Chella Jan 13 '16 at 06:43
  • You use the solution I gave you instead – Borodin Jan 13 '16 at 06:44

1 Answers1

0

try the following code:

$string =~ m/\..*?(grep.*?code)/;
print "$1\n";
  • Thanks for your reply . When I am using this code following error has occur .[Use of uninitialized value $1 in concatenation (.) or string at str.pl line 13.] – Chella Jan 13 '16 at 08:23
  • Can you share the complete block of code so it would be easier to figure out the error as the solution that I've provide works perfectly fine for me. – abhishek.jain Jan 13 '16 at 09:05