I'm writing a source filter, and it's all funksome and groovy, and it
works. However, to do the filtering that I *really* want, I need to slurp
the entire source file before doing any munging. So far, I can only see
how to do a line at a time or $bytes at a time.
This doesn't work:
package Myfilter;
use strict;
use Filter::Util::Call;
sub import {
my($type, @args) = @_; # not used yet
my $status;
my $text;
filter_add(sub {
$status=filter_read(); # read a line at a time into $_
if($status > 0) { # read was successful
$text.=$_; # append to temporary storage
} elsif($status == 0) { # EOF
$text=~s/foo//g; # get rid of all foos
$_=$text; # and put back into $_
} else {
die("It's all gone pear-shaped.\n");
}
$status;
});
}
1;
and this does work:
...
filter_add(sub {
$status=filter_read();
s/foo//g;
$status;
});
...
Although obviously, that second one won't work when I want to take context
into account.
Can anyone help me out here? The documentation is somewhat ... opaque.
--
David Cantrell | [EMAIL PROTECTED] | http://www.cantrell.org.uk/david/
Any technology distinguishable from magic is insufficiently advanced