props has asked for the wisdom of the Perl Monks concerning the following question:

Dear Monks i need your help once again . Here the code:
sub save_button { open WRITEFILE , ">>$time.txt" or die "write error\n"; my $format = ( " %10s\n" x @totalexpenses .%10s\n" x @totalexpenses ) +; printf WRITEFILE $format, @totalexpenses , @totalcosts; close WRITEFILE; }
i can run successfully without the @totalcosts array. There is a syntactic error in there which i cannot find out

Replies are listed 'Best First'.
Re: printf syntac
by ikegami (Patriarch) on Sep 26, 2007 at 21:05 UTC
    ( " %10s\n" x @totalexpenses .%10s\n" x @totalexpenses ); _______ ______________ | | | | v v " %10s\n" @totalcosts
Re: printf syntac
by FunkyMonk (Bishop) on Sep 26, 2007 at 22:15 UTC
    I think ikegami's reply needs some expanding:

    • Your second format is missing the opening quote
    • You want to print @totalexpenses and @totalcosts, but you're using @totalexpenses twice to create your format

    Try

    my $format = " %10s\n" x @totalexpenses . "%10s\n" x @totalcosts;

    update: s/elaborat/expand/

      pen WRITEFILE , ">>$time.txt" or die "write error\n"; my $format = " %10s\n" x @totalexpenses . "%10s\n" x @totalcosts; printf WRITEFILE $format, @totalexpenses . @totalcosts;
      I think those two @totalexpenses . @totalcosts conflict.

        Change
        printf WRITEFILE  $format, @totalexpenses . @totalcosts;
        back to
        printf WRITEFILE  $format, @totalexpenses, @totalcosts;