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

Hey Everyone, I know that this is going to be a dum question. In UNIX if you use >> that means to append to the end of a file. What I'm trying to do is append output to a file as my script runs. But, I'm not sure where to put the append at. When I use it (as shown in the example) I get some sort of mathmatical error. Can anyone help?
if (-d $file) { print "\nDirectory: $file\n" >> "test.txt"; &scandir($file); next; }
This little piece of code, if from something I'm working on. Please help!

Replies are listed 'Best First'.
Re: Appending to a file
by Trimbach (Curate) on Oct 20, 2000 at 00:14 UTC
      Thanks for the help. I found what I was looking for. Thanks again. curtisb
(ar0n: moderately offtopic) Re: Appending to a file
by ar0n (Priest) on Oct 20, 2000 at 00:43 UTC
    Just for the record, the "mathmatical error" [sic] applies to your use of >> which is the right bit-shift operator, where each bit is shifted to the right by n places (in digit >> n):
    my $one = 8; my $two = 2; # right shift 8 by 2 places # 00001000 (binary 8) becomes 00000010 (binary 2) print $one >> $two; # prints 2

    [ar0n]

RE: Appending to a file
by Albannach (Monsignor) on Oct 20, 2000 at 00:17 UTC
    You don't have a file open to append to. Try (untested) open(LOGFILE, '>>test.txt') or die"Can't append: $!";

    and your print statement becomes print LOGFILE "\nDirectory: $file\n";

Re: Appending to a file
by curtisb (Monk) on Oct 20, 2000 at 10:04 UTC
    OK, I know that it was a basic question that all Perl programmers should know. I forgot and I just asked thanks for the reminder. I'm sure that I will not forget this answer. curtisb
Re: Appending to a file
by runrig (Abbot) on Oct 20, 2000 at 00:18 UTC