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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.