[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] newbie - how to chop a file into more than one




    ##  Hi Mark,

    ##  to excerpt "bordered" data from a file you can do this:
open IN, "<MyDataSource.dat"      ;##   or die "Not found.";
    ##  uncomment the previous line and enter your file name
    ##  and of course erase the following 13 lines:

$content = "
Bla bla bla and nonsense ...
***** Start of Data *****
line 1 of precious data
line 2
line 3 etc.
**** End of Data *****
bla bla bla bla
rubbish and litter
***** Start of Data *****
line 11
line 12
line 13 etc.
**** End of Data ***** ";

while (<IN>)  {
  $content .= $_ }
$content =~
    s/(\*\*\*\*\* Start of Data \*\*\*\*\*.*?\*\*\*\* End of Data
\*\*\*\*\*)/push @harvest, $1/sge;
   ##   concerning that  .*?  in the above line starting s/( ...
   ##      look into the "Programming Perl" book, index: greedy
   ##      in order to understand this nongreedy pattern matching.
   ## The array  @harvest  should contain what you want:

for (@harvest)  {
  print "\n= = = Data chunk No.".++$i."\n", uc($_);  }
   ## or some other data manipulation

   ## Yours
   ##  Detlef Lindenthal <detlef»lindenthal.com>


Mark Bedish wrote:

> To All,
>
> Please excuse my ignorance.
>
> I am searching for specific start and end points in a file so that I can
> split it up and then work on replacing characters in each section. There are
> upto 100 or so start and end points.
>
> Example
>
> ***** Start of Data *****
> line 1
> line 2
> line 3 wtc
> **** End of Data *****
>
> I am sure it is easy and I have looked at the books but being new to it,
> just can't fathom it out!
>
> Many thanks for assistance.
>
> Regards
>
> Mark
> Surrey,UK
>


# ===== Want to unsubscribe from this list?
# ===== Send mail with body "unsubscribe" to macperl-request@macperl.org