mikael-g has asked for the wisdom of the Perl Monks concerning the following question:

my old robot is working bad what is up ...
what i used to delete a line from a text file ..the code below
what is wrong ???

#!/usr/bin/perl # # # # $filename='she.txt'; # use strict; use Tie::File; my $cnt = 0; open(FILE, "she.txt") or die "$!"; while(<FILE>) { if ($_ =~ /^she/) { &del($cnt); } $cnt++; } sub del { my $dex = $_[0]; tie my @file, "Tie::File", "she.txt"; splice @file, $dex, 1; $cnt--; }

Replies are listed 'Best First'.
Re: my old robot
by fglock (Vicar) on Jun 14, 2003 at 20:54 UTC

    You should tie the file globally, that is, outside the "del" subroutine. The best place is probably just after "open".

    But then, don't read the file in "while" - you can just use the tied array instead.