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

perl -wle 'open (F, ">test"); print F chr(26) . "Wont get in"; close(F +);'
or
perl -wle "open (F, '>test'); print F chr(26) . 'Wont get in'; close(F +);"
If you prefer Win32
Either way i cant get it right.. How do i escape the eof ?
any ideas?
Cheers Aquitaine

Edit kudra, 2002-02-23 Added to title

Replies are listed 'Best First'.
Re: chr(26)
by Chady (Priest) on Feb 22, 2002 at 20:22 UTC

    since you mentioned Win32: try binmode on your filehandle.. it will get it right


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.

    Chady | http://chady.net/
Re: chr(26)
by dmmiller2k (Chaplain) on Feb 23, 2002 at 04:22 UTC

    The problem isn't putting the string into the file, I think. The problem is confirming that the string got into the file. With your example, assuming all 12 characters get written to the file, using the DOS 'type' command (or any DOS-based program, like 'edit') will stop reading at the EOF character (chr(26)). Also, if you open the file from perl (or C++, etc.) in text mode, you won't see anything after the EOF, whther or not it's there.

    Opening the file in binary mode for writing can't hurt either.

    dmm

    If you GIVE a man a fish you feed him for a day
    But,
    TEACH him to fish and you feed him for a lifetime
Re: chr(26)
by premchai21 (Curate) on Feb 22, 2002 at 20:16 UTC
    $ perl -wle 'open (F, ">test"); print F chr(26) . "Wont get in"; close +(F);'; cat test Wont get in

    is what I get. perl v5.6.1 on i686-pc-linux-gnu. What do you mean by "escape the eof" and "get it right"? -- what is the question exactly?