You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@subversion.apache.org by "David M. Jones" <dm...@ams.org> on 2006/06/19 18:24:02 UTC
Re: checkout to stdout (cvs -p)?
My apologies for a post that is both belated and somewhat off-topic,
but I recently learned something about file handles in Perl that I
wish I had known before I replied to this thread in May.
The original question was how to get the SVN::Client cat method to put
its output in a perl variable rather than writing it to a file:
$ctx->cat (\*STDOUT, 'http://svn.collab.net/repos/svn/trunk/README',
'HEAD');
I posted a quick and dirty hack that I called StringHandle.pm that
used perl's tie mechanism to tie a file handle to a variable, after
failing to find anything comparable on CPAN.
It turns out I was doubly hasty. First, I somehow overlooked at least
two CPAN packages that implement fully what I implemented only
partially:
http://search.cpan.org/~dskoll/IO-stringy-2.110/lib/IO/Scalar.pm
http://search.cpan.org/~gaas/IO-String-1.08/String.pm
Second, as noted in the documentation for IO::String, perl 5.8 has
built-in support for in-memory files. Just give open a reference to a
scalar in place of a filename, e.g.:
#!/usr/bin/perl -w
use strict;
use warnings;
use SVN::Client;
my $SVN = SVN::Client->new();
my $buffer;
## Open a string for writing:
open(my $fh, ">", \$buffer) or die "Can't open \$buffer for writing: $!\n";
my $target = 'http://svn.collab.net/repos/svn/trunk/README';
$SVN->cat($fh, $target, 'HEAD');
close($fh);
## It's a real string:
$buffer =~ s/Subversion/SVN/g;
## You can also open strings for reading as well as writing:
open($fh, "<", \$buffer) or die "Can't open \$buffer for reading: $!\n";
my $lineno = 0;
for my $line (<$fh>) {
print $lineno++, ": ", $line;
}
close($fh);
__END__
Cheers,
David.
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org