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

Re: I'm having a strange bug with basic file input. I'm a total newb.

by Crackers2 (Parson)
on Dec 05, 2008 at 10:49 UTC ( [id://728249]=note: print w/replies, xml ) Need Help??


in reply to I'm having a strange bug with basic file input. I'm a total newb.

Inside your loop you're reading into $name instead of $studentname. I'm not sure how your sample output still manages to print the correct names, since your printf uses $studentname as well.

You're also forgetting about the line terminators. The first time you'll correctly read the name and scores. The second time your name will actually contain the line feed from the first line followed by the first 19 characters of the second name (or 18 if it's CR/LF instead of just CR)

For each subsequent line things will keep shifting. That's probably why you never find the "END".

Replies are listed 'Best First'.
Re^2: I'm having a strange bug with basic file input. I'm a total newb.
by KingCupons (Initiate) on Dec 05, 2008 at 10:52 UTC
    Argh...I put in the wrong code up here, then. I've been experimenting so much, and nothing works.
    Even with that fixed, it still doesn't work. I'll change the code. The varnames, anyway...Line terminators? -_-

      Try adding <INPUT>; after both of these lines

      read (INPUT, $test4, 3);

      That will read/skip the linefeed which would otherwise remain on each line.

      (And also fix $name --> $studentname, of course.)

        Or just drop the read calls altogether and do something like:
        $line=<INPUT>; $studentname = substr($line,0,20); $test1 = substr($line,21,3); ...

        (Though I'm sure a few monks can come up with an unpack solution or a module that handles fixed-width fields)

        Well, I've tried everything so far...Still no luck. :|

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others rifling through the Monastery: (5)
As of 2024-04-24 22:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found