[ale] perl question
Jerry Swann
ccoprjs at oit.gatech.edu
Mon May 10 09:28:55 EDT 1999
Mail from David S. Jackson, Mon, May 10, 1999 at 05:16:01AM +0000:
> sub remove_task {
> $num = 0;
> system( "clear" );
> open DATAFILE, "</home/dsj/.planner/data.txt" or die "\nCan't open $datafile: $!\n";
> print "\nNo. Pri.\tDescription\n";
> print "=========================================================\n\n";
> while (<DATAFILE>) { push @lines, "$_"; }
> foreach $line (sort @lines) {
> print "$num $line";
> $num++;
> }
> print "\nWhat task number is complete?";
> close DATAFILE;
> chomp($donetask = <STDIN>);
> open OUTFILE, ">/home/dsj/.planner/data.txt" or die "\nCan't open $datafile for writing: $!\n";
> splice @lines, $donetask;
> for ( $num = 0; $num < @lines; $num++) {
> print OUTFILE $line[$num];
> }
> close OUTFILE; $entry = ""; @lines = "";
> }
The final line above in the remove_task subroutine is defining
@lines to have a single element equal to "". Either change this to
'@lines=()' or put a 'my @lines' up at the top to make the variable's
scope local to this subroutine.
> No. Pri. Description
> =========================================================
>
> 0 1 A Continue programming well
The "0 " is being printed because of the extra "" element that gets added
after running the subroutine once.
--
Jerry Swann "Jerry dot Swann at oit dot gatech dot edu"
Georgia Institute of Technology
Office Phone: 404 894-1659
Office Fax: 404 894-9548
More information about the Ale
mailing list