How can I conditionally insert lines when using Tie::File?

Posted by thebourneid on Stack Overflow See other posts from Stack Overflow or by thebourneid
Published on 2010-06-14T03:06:10Z Indexed on 2010/06/14 10:02 UTC
Read the original article Hit count: 213

Filed under:

How can I change this code to insert lines if missing without deleting existing ones?

tie my @lines, 'Tie::File', $fn or die "could not tie file: $!";          

for (my $i = 0;  $i < @lines; $i++) {

   if ($ln_title == 0) {                            

      if ($i < $#lines and $lines[$i] =~ /(\s+TRACK \d\d .*)$/) {        

         $lines[$i+1] = '    TITLE ""';
      }
   }
}                      

untie @lines;

© Stack Overflow or respective owner

Related posts about perl