sureshr has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
I want to extract some data that are within blocks BEIGN and END, as below

my $test_data_001 = "__BEGIN_DATA__\nData1\nData2\nData3\n__END_DATA__ +";


When I try to extract data from the above line by a code piece of something like  if ($test_data_001 =~ /__BEGIN_DATA__\n(.*)\n__END_DATA__/) { # some action }, does not really match anything. Any solution is really appreciated.
Thanks,
Suresh R
ps: For some reason the "<code>" tag does'nt seem to work in my preview :(
pps: I have already tried  local $/ = undef; in the scope of that matching expression

20040211 Edit by Corion: Fixed code tags to make them work

Replies are listed 'Best First'.
Re: Extract data from a line with multiple newlines in it
by kvale (Monsignor) on Feb 11, 2004 at 08:54 UTC
    To match .* across multiple newlines, use the //s switch:
    if ($test_data_001 =~ /^__BEGIN_DATA__\n(.*)\n__END_DATA__$/s) { # some action }
    The //s switch treats the whole string as a single line by allowing . to match a newline.

    -Mark

      Thats precisely what I wanted!
      Thanks,
      Suresh R