Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

what's appens with this FH ??

by Discipulus (Prior)
on Oct 19, 2002 at 16:49 UTC ( #206527=perlquestion: print w/replies, xml ) Need Help??
Discipulus has asked for the wisdom of the Perl Monks concerning the following question:

Hello monks
I try learn to code, testing and retesting.. It pass a very strange think: I find the text of my code in the output!!

open (TEMPO, "+>c:\\winnt\\temp\\hash.tmp"); print (TEMPO "aba uba\niba seba\njak yuk\n"); ############open (TEMPO, "<c:\\winnt\\temp\\hash.tmp"); while (<TEMPO>) { print; }

If you uncomment the new open all runs normally 'cause Perl close th FH and reopen it for reading.
But, without commenting this line why I find in my output file a slice of my code ???
and on the screen some garbage and smiles ??
cheers for any explication

PS may be I have not to code when I have fever??

Replies are listed 'Best First'.
Re: what's appens with this FH ??
by krusty (Hermit) on Oct 19, 2002 at 17:17 UTC
    The first open opens c:\winnt\temp\hash.tmp for reading and for writing, but you didn't do a seek to the beginning of the file when you started reading.
    Perhaps another wise monk could explain here, but I'm going to guess that since the file was never closed, its not reading an end of file marker and is just pushing out whatever is left in its stack.
    You may have noticed the print statement never prints out to STDOUT

    aba uba
    niba seba
    njak yuk

    Add a seek and all may be well again:
    #!/usr/bin/perl -w open (TEMPO, "+>c:\\winnt\\temp\\hash.tmp"); print (TEMPO "aba uba\niba seba\njak yuk\n"); ############open (TEMPO, "<c:\\winnt\\temp\\hash.tmp"); seek TEMPO, 0, 0; while (<TEMPO>) { print; }

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://206527]
Approved by Aristotle
[1nickt]: Ah, you got Linus' fave? With Ubuntu? 4k display?
[1nickt]: ( The 17" monster I just bought is for my wife, who doesn;t leave the house with it...)
[Corion]: 1nickt: No, I'm using it with Windows 10, but with the 4k display, yes. It's a very nice build IMO, and relatively sturdy. Also, it got 8 or 9 on the ifixit repair scale, which I consider good
[Corion]: ... especially as I expect to have to replace the battery set in two or three years' time
[1nickt]: Nice. So happy that Dells are still user-repairable. Unusual these days.
[1nickt]: I will certainly not be buying any more Macs.
[Corion]: 1nickt: Yeah, or at least, I hopoe so ;)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (12)
As of 2017-03-27 13:10 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (320 votes). Check out past polls.