Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: IO::Tee problem (Well, problem with my brain, anyway)

by apl (Monsignor)
on Mar 23, 2009 at 11:11 UTC ( #752552=note: print w/replies, xml ) Need Help??


in reply to IO::Tee problem (Well, problem with my brain, anyway)

Your code contains:
open my $read, '<', 'Fanggame.txt'; open my $write, '>>', 'Fanggame.txt';

That is, you open for input and appending for output the same file.

Every time you run the program, you should double the size of your input file. Run it again; how much longer does the file get?

Replies are listed 'Best First'.
Re^2: IO::Tee problem (Well, problem with my brain, anyway)
by pobocks (Chaplain) on Mar 23, 2009 at 16:26 UTC

    The problem is that the input file triples, while the output file doubles.

    As far as I can tell, I'm slurping the entire file (previous to any additions), and then foreaching over a simple array and printing the file once. I should get a doubled copy in the input file, and a single copy in the output file.

    I've checked (with a print statement) and @lines contains only a single copy of the input file.

    for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";
      Why do you want to echo your input back to your input file?

        I was testing a statement made in Intermediate Perl; I don't really have a concrete use in mind. Right now, my main goal is to find out why it's doubling the output, so I can know how it works (and what I'm missing/doing wrong, assuming it's not an oddity in IO::Tee or something).

        for(split(" ","tsuJ rehtonA lreP rekcaH")){print reverse . " "}print "\b.\n";

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://752552]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (7)
As of 2023-02-07 14:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    I prefer not to run the latest version of Perl because:







    Results (40 votes). Check out past polls.

    Notices?