Perl Insert Lines

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 3:12 UTC
Read the original article Hit count: 325

Filed under:

How to 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