does not workDoes not work in which sense? USER NOTE doesn't get replaced? The file is garbled? The program dies? It never gets out of bed? What? Be specific!
Note : the file handle is opened in the following mode "+>>".Uhm, I'd be surprised if Tie::File works if all writes are forced to be at the end of the file. I'm also not convinced adding newlines in the middle of lines is a good idea with Tie::File - if you want to tie the file to an array, and the basic idea is to add a line, splice your line in.
But why are you using Tie::File anyway? What's the benefit? It seems to me you can do this in a single pass. Untested:
use autodie; open my $in, "<", "your-file"; open my $out, ">", "your-file.tmp"; while (<$in>) { print $out $_; if (/USER\s+NOTE/i) { print $out "@$global_variables_list\n"; last; } } while (<$in>) { print $out $_; } close $out; close $in; rename "your-file.tmp", "your-file";
In reply to Re: Inserting content into a file at a particular location
by JavaFan
in thread Inserting content into a file at a particular location
by perlpal
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |