RE: simple open file





|-----Original Message-----
|From: lance w [mailto:maelvo@xxxxxxxxxx]
|Sent: Tuesday, May 31, 2005 6:42 PM
|To: beginners@xxxxxxxx
|Subject: simple open file
|
|
|Hello,
|I'm trying to open (create if necessary) a file for APPEND, that will
|serve as a log. The script I'm using will open a file, but fails to
|print anything to it. Any advice?
|
|
|
|my $filename = "open_file.txt";
|open(APPEND, ">> $filename")
| or die "Couldn't open $filename for appending: $!\n";
| write "$subscriber\n";
|close APPEND;
|
|--
|To unsubscribe, e-mail: beginners-unsubscribe@xxxxxxxx
|For additional commands, e-mail: beginners-help@xxxxxxxx
|<http://learn.perl.org/> <http://learn.perl.org/first-response>
|

You havent specified the FILEHANDLE to write to in 'write'. 'write' will
write to the default filehandle (STDOUT by default, can be changed by
'select'ing any other valid filehandle).

Also, APPEND may be a bad choice of filehandle name.

my $filename = "open_file.txt";
open(LOGFILE, ">> $filename")
or die "Couldn't open $filename for appending: $!\n";
write LOGFILE "$subscriber\n";
close LOGFILE;


*********************************************************
Disclaimer:

The contents of this E-mail (including the contents of the enclosure(s) or attachment(s) if any) are privileged and confidential material of MBT and should not be disclosed to, used by or copied in any manner by anyone other than the intended addressee(s). In case you are not the desired addressee, you should delete this message and/or re-direct it to the sender. The views expressed in this E-mail message (including the enclosure(s) or attachment(s) if any) are those of the individual sender, except where the sender expressly, and with authority, states them to be the views of MBT.

This e-mail message including attachment/(s), if any, is believed to be free of any virus. However, it is the responsibility of the recipient to ensure that it is virus free and MBT is not responsible for any loss or damage arising in any way from its use

*********************************************************
.



Relevant Pages

  • Re: CMD.EXE and ">> logfile"
    ... Worth checking if you have any> instead of>> in any of your scripts.As you know> will overwrite the central.log file and *not* append.. ... All batch files write to a single logfile on the local disk, so I only need to check one logfile for problems. ... It seems to happen only when two batch files simultanously append a record to the bottom of the logfile. ...
    (microsoft.public.windows.server.scripting)
  • Re: How do I send stdout to file and stderr to both file & tty?
    ... they have to work in append mode. ... The program's standard output needs to be duplicated into the standard ... errors) to the logfile and show it as well: ... The shell's>> and tee -a are not actually using proper append mode on ...
    (comp.unix.shell)
  • dlmwrite append by column instead of new row
    ... I'm trying to write out to an very specific file format to be ... I think that dlmwrite will serve me ... suggestions how to append as new columns? ...
    (comp.soft-sys.matlab)
  • Re: dlmwrite append by column instead of new row
    ... I think that dlmwrite will serve me ... suggestions how to append as new columns? ... what you need to do is concatenate your data before writing, or if this is not possible, read the old data first, concatenate with the new, and overwrite the old data with the newly concatenated one. ...
    (comp.soft-sys.matlab)
  • Re: dlmwrite append by column instead of new row
    ... I think that dlmwrite will serve me ... suggestions how to append as new columns? ... 'roffset' and it didn't respond. ...
    (comp.soft-sys.matlab)