[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: checkout to stdout (cvs -p)?

From: David M. Jones <dmj_at_ams.org>
Date: 2006-06-19 20:24:02 CEST

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',

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


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');
    ## 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;


To unsubscribe, e-mail: users-unsubscribe@subversion.tigris.org
For additional commands, e-mail: users-help@subversion.tigris.org
Received on Mon Jun 19 20:25:49 2006

This is an archived mail posted to the Subversion Users mailing list.

This site is subject to the Apache Privacy Policy and the Apache Public Forum Archive Policy.