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

This node falls below the community's threshold of quality. You may see it by logging in.

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

    I don't believe you've read the errors returned from running this code. You'd have been alerted to the fact that you're missing a quotation mark. Don't ignore the errors returned when running your code. You don't seem to have any programming experience at all. You create a file called not.txt, in which you place perl code to open not.txt and overwrite it's contents with "hello!". I suggest you think about what you're doing.

    You've posted here many times on the subject of being "new to perl", and asking for answers to exam qustions. If you actually want to learn perl I suggest you read and understand at least some of the following:

      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 +.

        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);
Re^3: how to create a perl program using filehandle and streams ?
by Anonymous Monk on Apr 01, 2011 at 09:27 UTC
    show errors

    So what size shoes do you wear? :)

    Oh, maybe you can copy/paste the error message instead ;p

      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 +.
        Hold on! It looks to me that your perl program is called "not.txt" and then you are opening the same file for write, which will trucate it to zero bytes! That's like sitting on the branch of a tree and sawing it off next to the trunk.

        Call your program something like "not.pl", otherwise you will loose your code.
        A reply falls below the community's threshold of quality. You may see it by logging in.
    A reply falls below the community's threshold of quality. You may see it by logging in.