in reply to Looking for some insight on Tie::File

Line my @rows = @$ref; copies the entire file into memory, therefore changing this array, doesn't affect the file. The solution is to create an alias or to use the reference instead.

For example:

my $ref = [1,2,3]; local our @row; *row = $ref; push @row, 4; print @$ref; # prints: 1234
Or, simpler, push directly into @$ref:
my $ref = [1,2,3]; push @$ref, 4; print @$ref; # prints: 1234

Replies are listed 'Best First'.
Re^2: Looking for some insight on Tie::File
by stevieb (Canon) on Jan 09, 2016 at 00:42 UTC

    I'll ask straight up... why in the name of all things good are you advising to use symbolic references? After I read that, I found it hard to identify how this even answers the OP's question. There's no explanation of deref'ing a hash reference, and your use of local our ... seems way off as well.

    I very rarely take issue with posts here, but unless you wrote the code that OP has displayed, what you're saying is pretty bad advice.

      I'll ask straight up... why in the name of all things good are you advising to use symbolic references? After I read that, I found it hard to identify how this even answers the OP's question.

      Try it and you will see, it lets the OP use @array instead of $ref

        My bad... I'll re-state... "an unbounded, unconfined and completely dangerous assignment to a variable namespace that has global symbolic table access. This clobberes the symtab, which is *always* a bad idea, unless you *really* know what you're doing". No matter how you word it, it's very bad advice.

        Update: The people answering questions should *always* ensure their responses work properly without issue under the strict and warnings pragmas, and thereafter, advise the OP to do so as well.