in reply to Re^3: how to create a perl program using filehandle and streams ?
in thread how to create a perl program using filehandle and streams ?

the following error occured

C:\strawberry\perl\bin>perl not.txt Precedence problem: open not should be open(not) at not.txt line 1. String found where operator expected at not.txt line 2, near "print FI +LEHANDLE " " (Might be a runaway multi-line "" string starting on line 1) (Missing semicolon on previous line?) Bareword found where operator expected at not.txt line 2, near "print +FILEHANDLE "hello" (Do you need to predeclare print?) syntax error at not.txt line 1, near "not." Can't find string terminator '"' anywhere before EOF at not.txt line 2 +.

Replies are listed 'Best First'.
Re^5: how to create a perl program using filehandle and streams ?
by marto (Cardinal) on Apr 01, 2011 at 09:46 UTC

    I know, I told you what was wrong and what had to be fixed to get your code to overwrite itself with "hello!", which is what you seem to want to do for some reason.

    open (FILEHANDLE, ">not.txt") or die (Cannot open not.txt"); print FILEHANDLE "hello!"; close (FILEHANDLE);

    Should be:

    open (FILEHANDLE, ">not.txt") or die ("Cannot open not.txt"); print FILEHANDLE "hello!"; close (FILEHANDLE);

    Had you read any of the links I provided you'd be using something like:

    use strict; use warnings; use diagnostics; open (FILEHANDLE, ">not.txt") or die ("Cannot open not.txt"); print FILEHANDLE "hello!"; close (FILEHANDLE);

      Wow! when i run the following script then hello! can be seen inside "not.txt" file after once scrip is run

      use strict; use warnings; use diagnostics; open (FILEHANDLE, ">not.txt") or die ("Cannot open not.txt"); print FILEHANDLE "hello!"; close (FILEHANDLE);

      it means book assumed me as knower of perl so it didn't mentioned to write

      use strict; use warnings; use diagnostics;

      before that script.anyway in the book above example the line is" Here's an example in which we open a file for output and print some text to that file". So i think it just replaced(or write) that whole script into word "hello"! and if i write different word then that word will be there after scrip running.

        "Wow! when i run the following script then hello! can be seen inside "not.txt" file after once scrip is run."

        I've already questioned why you'd want to do this, you didn't answer.

        "it means book assumed me as knower of perl so it didn't mentioned to write:..."

        I have no idea what book you're talking about. For all I know this is explained in a previous section of the text. It's also possible that you didn't follow the books written instructions properly. I don't believe the book told you to save the perl script as not.txt, which the example script overwrites.