I am trying to use Filter::Simple to filter some code, specifically in the __DATA__ section. I followed the doc in Filter::Simple, and was able to get it to modify stuff in the __DATA__ section. Problem is that in my original code with __DATA__ (which has been filtered), the DATA now seems to have been processed already, which is a big problem.
Here is my filter: package F; use strict; use warnings; use Filter::Simple; FILTER { s/FOO/bar/g; # print qq(>>>\n$_<<<\n); # uncomment to see changed src }; #""; 1; Here's my sample program, filter commented out: #use F; use strict; use warnings; print "FOO is good\n"; while (<DATA>) { print; } __DATA__ Here is my FOO data. No FOO here. Run it, and I see this output: % perl U.pl FOO is good Here is my FOO data. No FOO here. Now, uncomment the "use F;", and I see this: % perl U.pl bar is good Here is my FOO data. No FOO here. Note that no text was changed in the DATA part. Now, uncomment the "" +line in the filter, so my filter is now this: package F; use strict; use warnings; use Filter::Simple; FILTER { s/FOO/bar/g; # print qq(>>>\n$_<<<\n); # uncomment to see changed src } ""; 1; Rerun, and I get this: % perl U.pl bar is good
Now, in filter, if you uncomment the print line, you will see that indeed the text is being changed. But apparently, since the __DATA__ block has already been read once, my program no longer sees it.

This is not good. Does anyone have a suggestion? After the filter runs (which I WANT to modify DATA area), I need to still be able to read data. This is for an application in Inline::C, by the way.

Any help/suggestions is much appreciated.

Thanks!


In reply to Filter::Simple and __DATA__ by bgiii

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.