Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

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

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


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

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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (None)
    As of 2024-04-25 00:00 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found