in reply to How to get rid of the errors in my perl script

In addition to the points made above by davido and Ratazong, the line:

if($pos[0] =/[0-9]/)

should be written as:

if ($pos[0] =~ /[0-9]/)

Likewise for the line:

if($pos[1] =/[0-9]/)

HTH,

Athanasius <°(((><contra mundum

Replies are listed 'Best First'.
Re^2: How to get rid of the errors in my perl script
by Anonymous Monk on Aug 09, 2012 at 09:51 UTC
    i have made all the possible corrections. but still i fail to get the proper output.
    open (my $fhConditions, "<1.txt"); my $l=6; open (my $read, "<2.txt"); my @e = <$read>; my $d = join('', @e ); $d =~ s/\s+//g; while (<$fhConditions>) { push (my @line, $_); my $count++; } for (my $i = 0; $i <$count; $i++) { my @pos = $line[$i] =~ /chr[0-9]\s+(.+?)\s/g; if($pos[0] =~/[0-9]/) { my $match = substr($d,$pos[0],$l); print "$line[$i]" if $match =~m/AAGCTT/; } if($pos[1] =~/[0-9]/) { my $a = $pos[0]-$l; my $match = substr($d,$a,$l); print "$line[$i]" if $match =~m/AAGCTT/; } }
    i doubt first of all its not getting the values it self from the array. i am not getting errors as well as output
      i am not getting errors as well as output

      That’s because you’ve removed

      use strict; use warnings;

      from the head of your script, although they were there in the original. With use strict restored, the errors return:

      Global symbol "$count" requires explicit package name at test.pl line +13. Global symbol "@line" requires explicit package name at test.pl line 1 +5. Global symbol "@line" requires explicit package name at test.pl line 1 +9. Global symbol "@line" requires explicit package name at test.pl line 2 +5. test.pl had compilation errors.

      You need to declare my $count and my @line before the while loop, so that they will still be visible in the following for loop:

      ... my (@line, $count); while (<$fhConditions>) { push @line, $_; $count++; } for (my $i = 0; $i < $count; $i++) { my @pos = $line[$i] =~ /chr[0-9]\s+(.+?)\s/g; ...

      See the section “Scope” in the “Functions” chapter of chromatic’s Modern Perl, available free online at http://modernperlbooks.com/books/modern_perl/.

      Note: In your original question, you gave a sample of the contents of your first input file (1.txt), but not of the second (2.txt), so it’s difficult to see what your script is trying to do.

      Athanasius <°(((><contra mundum