G'day fouinix,
Welcome to the monastery.
I see you have your answer to the FILE vs. \*FILE issue.
You seem to want to use an array. You don't say why or how you intend to use that array. I'm guessing that you want to avoid creating a disk file (for \*FILE). If you have follow-up questions, clarification of those points may be useful in providing a response.
In the following code, I've created a subroutine to (roughly) emulate what $ctx->cat(...) is doing: emulate_ctx_cat(\*FILEHANDLE, $target). There's two blocks of code: the first creates a disk file from $target (compare with choroba's example) and prints its contents; the second creates an array from $target, manipulates the data in that array, and then shows that $target has not changed.
#!/usr/bin/env perl use strict; use warnings; use autodie qw{:all}; use Tie::File; my $target_in = './pm_1073422_test.txt'; my $target_out = './pm_1073422_test.out'; print "*** Using Disk File ***\n"; { open my $fh_out, '>', $target_out; emulate_ctx_cat($fh_out, $target_in); close $fh_out; system cat => $target_out; unlink $target_out; } print "*** Using Array ***\n"; { open my $fh_out, '+>', undef; emulate_ctx_cat($fh_out, $target_in); tie my @text, 'Tie::File', $fh_out; print "* Original Text *\n"; print "$_\n" for @text; $text[2] = 'Modified line'; print "* Modified Text *\n"; print "$_\n" for @text; untie @text; close $fh_out; print "* Original File *\n"; system cat => $target_in; } sub emulate_ctx_cat { my ($fh_out, $target) = @_; open my $fh_in, '<', $target; while (<$fh_in>) { print $fh_out $_; } close $fh_in; }
Output:
*** Using Disk File *** Line 1 Line 2 Line 3 Line 4 *** Using Array *** * Original Text * Line 1 Line 2 Line 3 Line 4 * Modified Text * Line 1 Line 2 Modified line Line 4 * Original File * Line 1 Line 2 Line 3 Line 4
[If it's unfamiliar to you, see the documentation for open and Tie::File for an explanation of the syntax I've used.]
-- Ken
In reply to Re: Use SVN::Client to "cat" a file on svn
by kcott
in thread Use SVN::Client to "cat" a file on svn
by fouinix
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |