in reply to Re: While problem
in thread While problem

There isn't any errors!!! This is the outpur of the compiler:

GO:0000060GO:0000122GO:0000979GO:0001077GO:0001701GO:0001756 </p> <p> GO:0000060GO:0000122GO:0000979GO:0001077GO:0001701GO:0001756 </p>
I want for example only the first row!! Thanks!!

Replies are listed 'Best First'.
Re^3: While problem
by marto (Cardinal) on Oct 27, 2014 at 10:06 UTC

    "There isn't any errors!!!"

    Then you are not running the code you posted here. Don't bother posting code here which you aren't actually running, it's a waste of our time. As roboticus pointed out previously:

    "Try posting the code you actually run or don't gratuitously paste in a "use strict; use warnings;" at the beginning if you're not actually using them."

Re^3: While problem
by Corion (Patriarch) on Oct 27, 2014 at 10:07 UTC

    Then you are not running the script that you posted. Please make sure that the code you post and the code you run are the same.

Re^3: While problem
by Loops (Curate) on Oct 27, 2014 at 10:10 UTC

    For what it's worth, I get all the same errors marto saw. If you're not seeing any errors, what motivated these lines at the top of your script? :

    $main::mio; $main::mio2; $main::mio4; $main::words2;

    In your script there are a number of variables that haven't been prefixed with "my" when initially declared. Fixing those would be a good first step.

      Ok sorry for my habit i include strict and warning when i wrote here! This is my code and now isn't running!

      use strict; use warnings; use Data::Dumper; my $mio2; my $mio; my $line; my $line2; my $words; my $words2; my $i=0; my %go_accession_hash=(); open (FILE, "/Users/Pabli/Desktop/gene_association.goa_human"); open (FILE2, "/Users/Pabli/Desktop/go3.obo"); while(<FILE>) { my @array_with_all_fields=split(/\t/); if ($array_with_all_fields[2] eq "TP53"){ $mio=$array_with_all_fields[4]; open my $out_file, '>>', 'myoutputfilename.txt' or die "$!"; #print "".$mio."\n"; print $out_file $mio; # print to file } #print "".$mio."\n"; #} #%go_accession_hash=($mio,''); #my @test2= keys %go_accession_hash; #print "".$test2[0]."\n"; #print "".$mio."\n"; } open (FILE3, "/Users/Pabli/Documents/workspace/PerlProva/myoutputfilen +ame.txt"); while($line=<FILE2>){ $words2 = split(" ",$line); print "$words2[1]\n"; $i=2; while($line2=<FILE3>){ $i = $i - 1; if ($i >= 0) { $words = split(" ",$line2); #print $words[0]."\n"; } $mio2=$words[0]; #print "$words2[1]\n"; #print $words[0]."\n"; } #print "$words2[1]\n"; #print $words[0]."\n"; #$line= split(/\s+/); #if ($words2[0] eq "id:") { #$mio4=$words2[1]; #print $mio4."\n"; # } #elsif ($words2[0] eq "name:"){ #if ($mio4 == $mio2){ #print "name: ".$words2[1]."\n"; #} #} #} } close FILE; close FILE2; close FILE3;

      The error is about "words" and "words2". The program needs global declaration i think so (i did it at first row) but i don't know the way to do it. Thanks

        You seem to be highly confused about variables.

        $words and @words are two different variables in Perl. You are using $words[0], which accesses the variable @words. Maybe you want to read and learn perlvar and the syntax of variable names.

        So you're making some steps forward, that's good. You will help yourself if you always use strict and warnings.

        In addition to reading what Corion suggested, take a look at split and read the first sentence. What it returns depends on the calling context. Perl will be very confusing until you really understand what that means. Reading and absorbing Context tutorial should help.