Next Lightweight Databases 54

Tie::File Examples

How do I delete a line in a file?

     for $n (reverse 0 .. $#LINE) {
       if (is_snide_answer_to_FAQ($LINE[$n])) {
         splice @LINE, $n, 1;
       }
     }

or:

     my $spliced = 0;
     for $n (0 .. $#LINE) {
       if (is_snide_answer_to_FAQ($LINE[$n - $spliced])) {
         splice @LINE, $n - $spliced, 1;
         $spliced++;
       }
     }

or:

     @snide = grep is_snide_answer_to_FAQ($LINE[$_])), 0..$#LINE;
     for (reverse @snide) { splice @LINE, $_, 1 }


Next Copyright © 2003 M. J. Dominus