bgiii has asked for the wisdom of the Perl Monks concerning the following question:
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.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
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!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Filter::Simple and __DATA__
by johngg (Canon) on Mar 08, 2007 at 10:08 UTC | |
|
Re: Filter::Simple and __DATA__
by Anno (Deacon) on Mar 08, 2007 at 12:09 UTC |