Chris am Dienstag, 24. Januar 2006 22.35:
> Hi list,
>
> I am not sure if there is a proper name for this but was having some
> difficulty searching for it.
>
> Basically I have data in a file that is between two different
> characters, for example:
>
> # data data
> data
> data data data *
> # more dataaa
> moreeee *
>
> Basically I want to slurp that file in, then search for # and extract
> all the data up to the * and print it, new line, next set of data.

I assume you mean that the whitespace after '#' and before '*' is not part of 
the data (else, remove the \s* in the regex below).

The following just one (of the shorter) way to do it; read the expression 
beginning with 'print' bottom-up:

======
#!/usr/bin/perl

use strict;
use warnings;

local $/;
my $content=<DATA>;
print join "\n",
   map { do {$_=~s/\n/ /gs; $_} }
   $content=~/#\s*(.*?)\s*\*/gs;

__DATA__
# data data
data
data data data *
# more dataaa
moreeee *
======

see

perldoc -f map
perldoc -f do
perldoc perlre

and for opening/closing an external file:
perldoc -f open
perldoc -f close

hth, joe

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to