[ale] perl question
Eric Z. Ayers
eric.ayers at mindspring.com
Mon May 10 05:59:17 EDT 1999
Hi David,
If you try to print out the number '0' with a variable, you need to use
the int() clause around your stuff or else it will print a
space. Alsoyou need to use parenthesis if a number is the first
argument in your list when you use 'print()' because otherwise, it
assumes the first argument is a file handle.
$num=0;
print (int($num), " $line"));
-Eric
David S. Jackson writes:
> Hi,
>
> I'm writing this dinky little TODO planner script, and this one function is
> returning some goofy looking output, and I don't understand why it is:
>
> the function:
> =============
>
> #### Remove completed tasks ############################
>
> 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 "data.txt" file:
> ====================
>
> A Continue programming
> A Pick up check from Schwab
> B Update checkbook
> C Tidy up office
> A Make Linux Planner work
> B Website maintenance script
> C Check out some science fiction
> C This is still a test
>
>
> Weird looking output:
> =====================
>
> No. Pri. Description
> =========================================================
>
> 0 1 A Continue programming well
> 2 A Make Linux Planner nicer
> 3 A Pick up check from Schwab
> 4 B Update checkbook
> 5 B Website maintenance script
> 6 C Check out some science fiction
> 7 C This is still a test
> 8 C Tidy up office
>
> What task number is complete?
>
> ********************************
>
> Can anyone tell me why this occurs after one time through this function? Is
> the splice statement adding an extra at $line[0] ?? Also, it looks like
> I'm deleting more than the single array element I intended...
>
> Any and all help is appreciated! :-) Mind you, it's late, and I'm probably
> too tired to be writing this, but I'm too sleepy to know the difference...
> Zzzzz...
>
> :-)
> --
> David S. Jackson http://www.dsj.net
> =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
> "In theory, theory and practice are the same thing. In practice,
> they are different." -- Bruce Schnier
More information about the Ale
mailing list