Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much
 
PerlMonks  

Re: read CSV file line by line and create hash table

by james28909 (Deacon)
on Sep 20, 2014 at 01:18 UTC ( [id://1101318]=note: print w/replies, xml ) Need Help??


in reply to read CSV file line by line and create hash table

might i add my opinion here? you could manually read the file $bytes at a time and then store the data into a variable... its what i do with some files. take for instance in some files i work with, you read 8 bytes store into variable, read 8 more bytes and store into a different variable, then read 16 bytes and store that in a seperate variable. then you can call the variable at any time you need it. though i do not know if that would be best for this scenario, but if the file is aligned exactly the same throughout the file, you can just set it up top read bytes at a time. hope this helps :)

if you need example script id be more than glad to give if needed.

hope this is helpful and not off topic :)>

i do alot of work with header information, particularly ps3 flash information. in the header it describes the filesize, file location and file name in the header. and i loop thru that info to extract the actual data further in the file. if you need me to post some examples let me know :)
if your trying to extract data, just do it per each loop. or in other words, get filename size and name ect and then extract the data, then loop again. if you have a count of some sort it works a treat. otherwise there is the until loop which works as well, but a count works better. actually you could probably look thru my older post to get an idea of what i mean.
  • Comment on Re: read CSV file line by line and create hash table

Replies are listed 'Best First'.
Re^2: read CSV file line by line and create hash table
by james28909 (Deacon) on Sep 20, 2014 at 10:08 UTC
    check this out, works great if yoru extracting files referenced by the header ;)
    my $fileLocation = ''; my $fileSize = ''; my $fileName = ''; my $chunk = ''; #my $entry_Count = seek and read the count inside the file; $entry_Count =~ s/(.)/sprintf("%02x",ord($1))/egs; #print "There are $entry_Count entries in this file"; seek( $infile, 0x10, 0 ) || die "cannot seek file: $!"; for ( my $i = 1 ; $i <= $entry_Count ; $i++ ) { read( $infile, $fileLocation, 0x08 ); read( $infile, $fileSize, 0x08 ); read( $infile, $fileName, 0x20 ); $fileLocation =~ s/(.)/sprintf("%02x",ord($1))/egs; $fileSize =~ s/(.)/sprintf("%02x",ord($1))/egs; $fileName =~ s/\0+$//; print ("Found $fileName"); open( my $file, '>', "extracted/$fileName" ) || die "Cannot op +en $fileName $!"; binmode($file); seek( $infile, hex($fileLocation), 0 ); read( $infile, $chunk, hex($fileSize) ); syswrite( $file, $chunk ); #print ($file $chunk); close($file); } print "Files/Data extracted";
    the above will read a file in, and depending on an entry count (if one is defined in the file you are using) will extract the data that the header references. with the header being $entry_Count long ofcourse
Re^2: read CSV file line by line and create hash table
by james28909 (Deacon) on Sep 20, 2014 at 07:47 UTC
    it also looks as if your working with a file 16 mb in size. could you upload one of your files and let me take a look? :)
Re^2: read CSV file line by line and create hash table
by james28909 (Deacon) on Sep 20, 2014 at 11:29 UTC
    what was i downvoted for? it really disheartens me to get downvoted for just trying to help someone. and also nto to even get any feedback at all as to why i got the downvote :l

    i know i offer very limited help, but when it comes to something i think i can help with i dont hesitate and i give my opinion/advice whole heartedly. atleast tell me why you gave me a downvote <.<

    also it was already said once in this thread that.. and i quote... "But this is Perl, and There Is More Than One Way To Do It". and all i did was offer an alternative. a way to display all infos from the file header OR you could even extract it based off header references, and with a little reconstruction of the example script i posted, you could accomidate the needed data quite well.

    also the example script has a little code in it that other monks helped me with as well.

      First, relax, downvotes happen, you've got to wait a few days to see the final tally. Also see Why did I get downvoted?

      However, while it's true that TIMTOWTDI, your code isn't actually "one way to do it", since lshokri02 wants to read a CSV file, and your code does something very different (plus, it doesn't compile). Off-topic posts are not generally a bad thing, but this one should probably be more clearly described as such, otherwise it may send the person looking for answers down the wrong path. This is especially true for your first post, since it begins by describing a method that would not be particularly useful in reading a CSV file.

      (Also, posting 5 nodes all in reply to each other probably isn't necessary, as you could have edited your node. It makes it look like you didn't take the time to think about your post before submitting it.)

        i could easily remove the commas and parse the proposed file the way i described. anyways im not gonna argue with you man, you and other fellow monks have gave me alot of help here and i would like to continue with that help again if i ever need it :) hope you feel the same way.
      you know what lol, i dont even care anymore. it is merely your opinion to think the post i made deserves a downvote, unless you can give me actual physical proof as to why you downvote me, i could care less. downvote all my posts :)
      p.s. have fun

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others perusing the Monastery: (6)
As of 2024-04-19 10:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found