silly8888 has asked for the wisdom of the Perl Monks concerning the following question:
and that would output the string "Lorem ipsum dolor sit amet END" to the file. So far I have tried the following:open my $fh '>:via(Append)','/some/file'; print $fh "Lorem ipsum dolor sit amet "; close $fh;
but that doesn't work, the print in POPPED fails. Any ideas?package PerlIO::via::Append; sub PUSHED { my ($class,$mode,$fh)=@_; return -1 if $mode eq 'r' || $mode eq 'r+'; my $buf=''; bless \$buf,$class; } sub WRITE { my ($self,$buf,$fh)=@_; $$self.=$buf; length($buf); } sub FLUSH { my ($self,$fh)=@_; print $fh $$self or return -1; $$self=''; 0; } sub POPPED { my ($self,$fh)=@_; print $fh "\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Create PerlIO::via layer to append data at the end of a file
by ikegami (Patriarch) on Jun 15, 2010 at 19:41 UTC | |
by ikegami (Patriarch) on Jun 15, 2010 at 21:30 UTC | |
by silly8888 (Initiate) on Jun 16, 2010 at 04:46 UTC | |
|
Re: Create PerlIO::via layer to append data at the end of a file
by ambrus (Abbot) on Jun 16, 2010 at 13:49 UTC |