Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

Re: reading file into an array

by lostjimmy (Chaplain)
on Dec 05, 2008 at 20:53 UTC ( [id://728375]=note: print w/replies, xml ) Need Help??


in reply to reading file into an array

I think we're going to need to see more code. There is no way that you could be getting a multidimensional (read: array of arrays) array from reading a file. I'd like to see what you are doing

An easy fix to start on line 14 would be something like:

#!/usr/bin/perl use strict; use warnings; for (1..13) { <DATA>; } while (<DATA>) { print; } __DATA__ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

Replies are listed 'Best First'.
Re^2: reading file into an array
by vassago (Novice) on Dec 05, 2008 at 21:20 UTC
    When i cut the file into about 500 lines it worked fine, but with my test file of 2800 lines it put out the wrong output. I have it running. I used:
    while(<$file>){
    ...
    }
    and just used an arbitrary line counter to have it start processing the code once it hit line 14 and above. I just tested similar code but just had it read the file into the array and then print it out to a text file and checked the text file and it was all there so what I was seeing in eclipse was misleading (I think it breaks it into 1000 line chunks to make it easier to read through manually).
    And I totally just had an 'aha' moment. I was parsing the date out of each line to test it against another file I had to make sure the lines I was comparing are the same date and time. Initially I was only taking the date from line 14 because I at first didn't realize one file would have multiple dates. So when I changed it to parse the date from every line I forgot to change the date reading from
    $fileContents14 to $fileContents$x
    So it wasn't looking like it was going through all the info because the test of making sure the same date is being tested failed for the whole document. And when I tested with only 500 lines the date changed to the correct date within the first 14 lines.
    I don't know if much of that made sense without knowing what the program does and stuff but I now feel stupid for posting this question. I seriously played with this for hours before posting and couldn't figure it out, though.

      It has been my experience that the two best ways to solve a problem are:

      • Ask the question in public where lots of people can see what's confusing you.
      • Tell your boss you can't solve it.

      Either of these activities will cause the solution to manifest itself in very short order.

      G. Wade

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-23 14:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found