CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
help with extracting data points

 



effc
Novice

Nov 16, 2012, 9:09 AM

Post #1 of 3 (871 views)
help with extracting data points Can't Post

The jist of what I am doing is taking an excel file, and trying to match a data point from a column header and row, and remove each data point into a new file. This is what I have so far:



#!/usr/bin/perl
# parse an .xlsx output file and create single data file for each animal id/probe

print "JJ.xlsx\n";
$file = <>;
$file =~ s/\s+$//;
$counter = 0;
%nameHash = ();
open (JJ.xlsx, "$file" || die);
while ($line = <1000>)
{
if ($counter < 1)
{
$counter = $counter + 1;
@CODELINK_ID = split('\t', $line);
$CODELINK_ID = scalar(@CODELINK_ID);
$CODELINK_ID = $CODELINK_ID - 1;
$Count = 0;
print "$counter and $Count and $CODELINK_ID\n";
while ($Count < 0)
{
$Count = $Count + 1;
$nextArray = pop(@CODELINK_ID);
$nextArray =~ s/\s+$//;
$nextArray =~ s/\.txt//i;
open (OUT, ">$nextArray" || die);
print OUT "ID\n";
#close OUT;
$nameHash{$Count} = $nextArray;
print "$Count and $nextArray\n";
}
}
}


wickedxter
User

Nov 16, 2012, 5:11 PM

Post #2 of 3 (864 views)
Re: [effc] help with extracting data points [In reply to] Can't Post

remember to use the code blocks in the forum it helps in readability.... I went threw and i think i fixed what i saw that was wrong...


Code
#!/usr/bin/perl  
# parse an .xlsx output file and create single data file for each animal id/probe

print "JJ.xlsx\n";

my $file = <>;
my $file =~ s/\s+$//;

my $counter = 0;

my %nameHash = ();


open (my $file_handle, '<' , "$file" ) or die("Cant open $file, $!");
while ($file_line = <$file_handle>) {
if ($counter < 1) {
$counter = $counter + 1;
my @CODELINK_ID = split('\t', $file_line);
my $CODELINK_ID = scalar(@CODELINK_ID);
$CODELINK_ID = $CODELINK_ID - 1;
my $Count = 0;

print "$counter and $Count and $CODELINK_ID\n";

while ($Count < 0) {
$Count = $Count + 1;
my $nextArray = pop(@CODELINK_ID);
$nextArray =~ s/\s+$//;
$nextArray =~ s/\.txt//i;

open (OUT, ">$nextArray") or die("Cant open $nextArray, $!");
print OUT "ID\n";
close OUT;

$nameHash{$Count} = $nextArray;
print "$Count and $nextArray\n";
}
}
}



(This post was edited by wickedxter on Nov 16, 2012, 5:12 PM)


FishMonger
Veteran / Moderator

Nov 16, 2012, 5:31 PM

Post #3 of 3 (861 views)
Re: [effc] help with extracting data points [In reply to] Can't Post

If you actually are parsing an excel .xlsx, which is a binary file, you can't parse it as if it were a plain text file. You need to use one of the excel parser modules on cpan.

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives