switcherswitcherswitcherswitcher

User login

Who's online

There are currently 0 users and 3 guests online.

Who's new

  • fengzhixuan
  • tomas81
  • raju_dharna
  • sathisbioinfo
  • garfieldeatoldy

RSS Feeds

Technorati

Undefined variable error driving me insane

Hi guys,

Hoping that one of you can help me out with this error on the following script. It complains about the use of an unitialized value $sorted in string eq at line 84 (I've stuck a comment on the end of the line so you can find it easier), but I can't work out why the hell this isn't working. Any ideas would be greatly appreciated.

Cheers,
Mark QT.


#!/usr/bin/perl -w
@sections = ("BP");
#@sections = ("BP","CC","MF","KEGG");
$mouse1 = "AJ3";
$mouse2 = "AJ7";
open(OUTFILE, ">$mouse1 vs $mouse2.txt");
foreach $section(@sections){
$file1 ="$mouse1"."_"."$section".".jsp";
open(HTMLFILE1, $file1) || die "cannot open first HTML file";
@htmltext1 = ;
$i = 0;
$htmlstring1 = "";
foreach $htmltext1(@htmltext1){
$htmlstring1 = "$htmlstring1 $htmltext1";
}
$file2 ="$mouse2"."_"."$section".".jsp";
open(HTMLFILE2, $file2) || die "cannot open second HTML file";
@htmltext2 = ;
$j = 0;
$htmlstring2 = "";
foreach $htmltext2(@htmltext2){
$htmlstring2 = "$htmlstring2 $htmltext2";
}
close HTMLFILE2;

@names1 = ();
@benjamini1 = ();
@sorted1 = ();
@table1 = split(/GSearch\?query=/,$htmlstring1);
foreach $table1(@table1){
if(index($table1,"&mode=name") != -1){
push(@names1, substr($table1,0,index($table1,"&mode=name")));
$b = substr($table1,index($table1,"") - 8);
$b = substr($b,0,index($b,"") + 1);
push(@benjamini1, $b);
}
}

while($i ") - 8);
$b = substr($b,0,index($b,"") + 1);
push(@benjamini2, $b);
}
}

while($j

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Submitted by Mark Quinton-Tulloch on January 21, 2008 - 2:33pm.

ok, that didn't post properly, so here's the offending block of code, error is on the 4th line:

 foreach $sorted1(@sorted1){
    $i2 = 0;
    foreach $sorted2(@sorted2){
      if($sorted2 eq $sorted1){
        push(@bothlists,$sorted1);
        delete $sorted1[$i1];
        delete $sorted2[$i2];
      }
      $i2++;
    }
    $i1++;
  }   
 

Submitted by Daz on January 21, 2008 - 5:34pm.

Hi Mark,

That only sounds like a warning. Is the script still running despite that message?

It sounds like you could have an empty element in one of your arrays (@sorted1 or @sorted2). Try using Data::Dumper to see if there is data missing from them:

use Data::Dumper;
print Dumper(@sorted1);
print Dumper(@sorted2);
Submitted by j1n3l0 on January 22, 2008 - 3:16pm.

It seems like you may be deleting $sorted1[$i1] before you've finished with it.

Nelo

Smoothie, smoothie, hundre prosent naturlig!

Submitted by Mark Quinton-Tulloch on January 24, 2008 - 4:47am.

Cheers for the suggestions guys. I gave up and split it into two separate scripts which got the job done. Not elegant but I needed the results for an assignment and no programming was required for the assignment so code quality wasn't an issue, just saved me hours of manually comparing lists. Will try out your suggestions at some point as it was bugging the hell out of me but have ridiculous amounts of work to do at the moment and exams coming up so it will have to wait a while. Thanks for the help though.

Cheers,
QT.