mgamar has asked for the wisdom of the Perl Monks concerning the following question:

Hi everyone,

I try to run one script, and I get this message, I do not know what it's means

Use of uninitialized value $out in concatenation (.) or string at blas +tall_modificado line 20. readline() on closed filehandle $IN at blastall_modificado line 26. Use of uninitialized value $out in concatenation (.) or string at blas +tall_modificado line 80. is done

line

20 open my $OUT, '>', "$out.out"; 26 while (my $line = <$IN>){ 79 print "$out is done\n";

Now the errors are :

Global symbol "$out" requires explicit package name at script line 20.

Global symbol "$out" requires explicit package name at script line 79.

Execution of script aborted due to compilation errors.

#!/usr/bin/perl use warnings; use strict; my @outs; my %grupos1; my %grupos2; my @split; #my $out; my @element2; my @element1; open my $IN , '<', " $ARGV[0]"; open my $OUT, '>', "$out.out" or die "open failed: $!\n"; #########################---- while (my $line = <$IN>){ chomp $line; my @split = split /\t/, $line; my $id1 = join ("\t", @split); if (!defined $grupos1{$id1}) { $grupos1{$id1}= []; } #close defined hash %grupos1 if push @{$grupos1{$id1}}, [$split[0],$split[1],$split[2],$split[3],$ +split[4]]; }# close while close $IN; #----------------------------------- open my $IN2 , '<', "$ARGV[1]"; while (my $line2=<$IN2>) { chomp $line2; my @split2 = split /\t/, $line2; my $id2 = join ("\t", @split); if (!defined $grupos2{$id2}) { $grupos2{$id2}= []; } #close defined hash %grupos2 if push @{$grupos2{$id2}}, [$split2[12],$split2[1], $split2[10], $spl +it2[11]]; } #close while close $IN2; foreach my $key1 ( sort keys %grupos1 ) { for my $element1 ( @{ $grupos1{$key1} } ) { #derefrence foreach my $key2 ( sort keys %grupos2 ) { for my $element2 ( @{ $grupos2{$key2} } ) { if ( $element1->[0] eq $element2->[0]){ my $new_start= $element1->[2]+$element2->[2]; my $new_end= $element1->[3]+$element2->[3]; print $OUT, "$element1->[1]\t$new_start\t$new_end +\t$element2[1]\t.\t$element1[4].\t.$element2[0]\n"; } ## end if } #end foreach key1 } } #end foreach key2 } #end foreach key1 print "$out is done\n"; %grupos1 = (); #empty hash %grupos2 = (); #empty hash close $OUT; #} #close genome

Thanks you so much for your help

Replies are listed 'Best First'.
Re: I get these errors when I perform the script
by 1nickt (Canon) on Sep 17, 2015 at 04:35 UTC

    It's a little easier to see now that you've edited your post. But you still don't show the relevant part of your code. See PerlMonks FAQ#Posting-on-PerlMonks.

    All that can be seen from what you posted is that you twice try to use a variable $out that has not been initialized. In other words, it doesn't contain what you think it does. You should print() it out to see what's in it. Maybe you read it from a file and forgot to chomp() the newline character off the end?

    Of course since $out is uninitialized at line 20, your open() fails, but you don't know because you don't check, like this:

    open my $OUT, '>', "$out.out" or die "open failed: $!\n";

    You're also trying to read from a filehandle that hasn't been opened at line 26; put the same error check on that open() and see why the filehandle isn't open.

    The way forward always starts with a minimal test.
      yes, in fact in the docs for open is stated clearly:
      When opening a file, it's seldom a good idea to continue if the requ +est failed, so open is frequently used with die. Even if die won't do what you want (say, in a CGI script, where you +want to format a suitable error message (but there are modules that can help with that problem)) always check the retur +n value from opening a file.

      L*
      There are no rules, there are no thumbs..
      Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.
Re: I get these errors when I perform the script
by 1nickt (Canon) on Sep 16, 2015 at 21:55 UTC

    Welcome Adriana. Please edit your post and place your code (and the error message) inside <code></code> tags. Then someone will help you in no time.

    (You can edit your post by clicking on its title.)

    The way forward always starts with a minimal test.
Re: I get these errors when I perform the script
by Anonymous Monk on Sep 16, 2015 at 23:15 UTC
    You're missing a use autodie; at the top of your program