http://www.perlmonks.org?node_id=938673


in reply to Re: Tie::File Write Problem
in thread Tie::File Write Problem

That's my confusion, doesn't this line change the element in the line?
if($tmp[6] eq "6 Elm") {$tmp[6] = 'XXXXX'}
I am splitting each line up based on the commas in the line and changing that element

Replies are listed 'Best First'.
Re^3: Tie::File Write Problem
by toolic (Bishop) on Nov 17, 2011 at 19:57 UTC
    That line does not change the @lines array or the tied file. That just changes the @tmp array. Tip #4 from Basic debugging checklist:
    use Data::Dumper; print Dumper(\@tmp); print Dumper(\@lines);
Re^3: Tie::File Write Problem
by jethro (Monsignor) on Nov 17, 2011 at 23:35 UTC

    @tmp is a completely separate variable that is not tied to the file. The split copies the data. You would have to add the following inside the foreach-loop to change the file as you intented:

    $i= join(',',@tmp);

    Note that even this works only because $i actually is an alias to the data in @lines and not a copy (this is magic done by the foreach loop)

      Thanks - when I think it through it makes sense as to why it wasn't writing to the file!

      Rejoining the value back into the line works perfectly!