wog's home node
for japhy:
=-> cat test.pl
my($plaintext,$html);
$plaintext = ">> foo";
pipe(READ, WRITE);
print "about to open\n";
open WRITE, "| cat";
print WRITE $plaintext;
print "\njust wrote\n";
close WRITE;
print "\nclosed\n";
{ local $/; $html = <READ>; }
close READ;
print "\njust read\n";
print "\$html: $html\n"
=-> perl test.pl
about to open
just wrote
>> foo
closed
just read
$html:
#!/usr/bin/perl -w
use strict;
BEGIN {
package Date::Year1984;
use vars qw(@ISA);
require Tie::Handle;
@ISA = qw(Tie::StdHandle);
sub samecase {
my($what,$pat) = @_;
$what = lc $what;
for my $i (0..length($pat)-1) {
substr($what,$i,1) = uc substr($what,$i,1)
if substr($pat,$i,1) eq uc substr($pat,$i,1);
}
return $what;
}
sub filter {
s/\b4\b/5/g, s/\b(four)\b/samecase("five",$1)/ieg for @_;
}
sub WRITE {
my @x = @_;
filter($x[1]);
Tie::StdHandle::WRITE(@x);
}
tie *STDOUT, 'Date::Year1984', '>&STDOUT';
tie *STDERR, 'Date::Year1984', '>&STDERR';
$SIG{__DIE__} = sub { local @_ = @_; &filter; die(@_); };
$SIG{__WARN__}= sub { local @_ = @_; &filter; warn(@_) };
} # end of BEGIN{}
package main;
print "2 + 2 = 4.\n";
warn "2 + 2 = 4 not 5!\n";
die "saying two and two makes FOUR! (I love Big Brother!)\n";
No comment.
Search Results
|