use of uninitialised value

C

Cognition Peon

I am getting desried output for the following piece, but -w switch to perl
is reporting that 'if />.*/' in the code uses uninitialized value. The
input file follows. I also tried another combination of if statement, but
the error still persists. 'if /^(>.*)/' accessing the match from $1.


while(<FILE>) {
my ($header, ) = ();
next if /^$/;
chomp;

if (/>.*/) { # Use of uninitialized value here
$header = $&;
$bin = (split('[_-]', $header))[1];
push @{$bins{$bin}}, $header;
} else {
$fasta{$header} = $_;
}
}
close(FILE);
uTSLPxov-bin3-005614 TAATTTAGAAAAAATCATGGCCCCACATTTTGTCAAGGATTCTTACAAGTGATATTCAAATATCTAATCTAAAATGATTATCTAGAAATTGGCACATTCTAAGTGTGCAGATGCTGATGAGGAGCAGGTATTGATAGACAGCGCGTTATG[C/T]GTCAAAGGATGTCTATCCTTTGCTAAAGTGTTACTCTGACTATGCTGTAAAAAGCAGGAGGTAAGAGCTTAAGAAAGAGGAGTAAAAGAGATAATTCTCATGAGATAAACTCTAAGGATTGATGCTGTGCTCCAGGTCTCTCCAGTGTTT
uTSLPxov-bin4-005119
AAAGAGCCCGTAGGCGTTTAGGTGTTATATAGTGCAGCCAGAAAGCTCTGGAGCATCAGGGAGACTCCAACTTAAGGCAACAGCATGGGTGAATAAGGGCTTCCTGTGGACTGGCAATGAGAGGCAAAACCTGGTGCTTGAGCACTGGCC[C/T]CTAAGGCAGGCCTTACAGATCTCTTACACTCGTGGTGGGAAGAGTTTAGTGTGAAACTGGGGTGGAATTGGGTGTCCACGTATGTTCCCTTTTGCCTTACTATATGTTCTGTCAGTTTCTTTCAGGAAAATCTTCATCTTACAACTTGTA
uTSLPxov-bin4-006317
ACCCTCTTTGTCCTATTTTTCTTTCTTCCAGACCAAAAGTACCGAGTTCAACAACACCGTCTCTTGTAGCAATCGGGTGAGTAGAGAGTTCAGTGCTGCTGGCTTTCTCCAGGGAGACGCCAGGCATTTTGGAGAGGGAGTATCCTGCTA[C/T]GTGCAGAACTCCGAGAGGTGCCTGGGCTCCGGGACGCCGCCGCCGGGGGAAAGGGGACATCTGGGCTGTCAGAGCGGGGCTGCGCCTAGCTTGGGACAACACTTCTGTTCCAATTTAGGGAGAGGAAGTCTCTATCCGGAGGAAAGGCAA
 
C

Cognition Peon

8:39pm, IP packets from Cognition Peon delivered:
I am getting desried output for the following piece, but -w switch to perl
is reporting that 'if />.*/' in the code uses uninitialized value. The
input file follows. I also tried another combination of if statement, but
the error still persists. 'if /^(>.*)/' accessing the match from $1.


while(<FILE>) {
my ($header, ) = ();

initializing $header for every line in the file is causing the problem.
just figured it..
next if /^$/;
chomp;

if (/>.*/) { # Use of uninitialized value here
$header = $&;
$bin = (split('[_-]', $header))[1];
push @{$bins{$bin}}, $header;
} else {
$fasta{$header} = $_;
}
}
close(FILE);
uTSLPxov-bin3-005614 TAATTTAGAAAAAATCATGGCCCCACATTTTGTCAAGGATTCTTACAAGTGATATTCAAATATCTAATCTAAAATGATTATCTAGAAATTGGCACATTCTAAGTGTGCAGATGCTGATGAGGAGCAGGTATTGATAGACAGCGCGTTATG[C/T]GTCAAAGGATGTCTATCCTTTGCTAAAGTGTTACTCTGACTATGCTGTAAAAAGCAGGAGGTAAGAGCTTAAGAAAGAGGAGTAAAAGAGATAATTCTCATGAGATAAACTCTAAGGATTGATGCTGTGCTCCAGGTCTCTCCAGTGTTT
uTSLPxov-bin4-005119
AAAGAGCCCGTAGGCGTTTAGGTGTTATATAGTGCAGCCAGAAAGCTCTGGAGCATCAGGGAGACTCCAACTTAAGGCAACAGCATGGGTGAATAAGGGCTTCCTGTGGACTGGCAATGAGAGGCAAAACCTGGTGCTTGAGCACTGGCC[C/T]CTAAGGCAGGCCTTACAGATCTCTTACACTCGTGGTGGGAAGAGTTTAGTGTGAAACTGGGGTGGAATTGGGTGTCCACGTATGTTCCCTTTTGCCTTACTATATGTTCTGTCAGTTTCTTTCAGGAAAATCTTCATCTTACAACTTGTA
uTSLPxov-bin4-006317
ACCCTCTTTGTCCTATTTTTCTTTCTTCCAGACCAAAAGTACCGAGTTCAACAACACCGTCTCTTGTAGCAATCGGGTGAGTAGAGAGTTCAGTGCTGCTGGCTTTCTCCAGGGAGACGCCAGGCATTTTGGAGAGGGAGTATCCTGCTA[C/T]GTGCAGAACTCCGAGAGGTGCCTGGGCTCCGGGACGCCGCCGCCGGGGGAAAGGGGACATCTGGGCTGTCAGAGCGGGGCTGCGCCTAGCTTGGGACAACACTTCTGTTCCAATTTAGGGAGAGGAAGTCTCTATCCGGAGGAAAGGCAA
 
T

Tore Aursand

I am getting desried output for the following piece, but -w switch to perl
[...]

Just a recommendation: If you're using Perl 5.6.1 (or newer), you should
drop '-w' and use 'use warnings' instead;

#!/usr/bin/perl
#
use strict;
use warnings;
[...]
is reporting that 'if />.*/' in the code uses uninitialized value. The
input file follows. I also tried another combination of if statement, but
the error still persists. 'if /^(>.*)/' accessing the match from $1.

while(<FILE>) {
my ($header, ) = ();

Hmm. What is this?
next if /^$/;

And this? Are you trying to match empty lines? No need for a regular
expression for that.

You should try to do this a immediate as possible.
if (/>.*/) { # Use of uninitialized value here

Have in mind that the warning might refer to something within the scope of
that 'if' statement.
$header = $&;

Do you _really_ need to use '$&'? Take a look at 'perldoc perlvar':

[...]
The use of this variable anywhere in a program imposes a considerable
performance penalty on all regular expression matches. See "BUGS".
$bin = (split('[_-]', $header))[1];

Maybe it's just me, but I don't see the string '[_-]' in the data you're
reading? What are you _really_ trying to do? Match the part of the
string _after_ the '[C/T]' string?
$fasta{$header} = $_;

'$header' will always be undefined here. You never set it to something
withing that scope.

If so (untested and might not even do what you want it to):

while ( <FILE> ) {
chomp;
next unless ( length );

if ( m,\[C/T\](.*)$, ) {
push( @{$bins{$1}}, $_ );
}
else {
# Not sure what you really want to achieve/do here
}
}
 
U

Uri Guttman

CP> I am getting desried output for the following piece, but -w switch to perl
CP> is reporting that 'if />.*/' in the code uses uninitialized value. The
CP> input file follows. I also tried another combination of if statement, but
CP> the error still persists. 'if /^(>.*)/' accessing the match from $1.


CP> while(<FILE>) {
CP> my ($header, ) = ();

huh? my $header is fine.

CP> next if /^$/;
CP> chomp;

CP> if (/>.*/) { # Use of uninitialized value here

are you sure about that line number? assuming you read a line into $_,
that is matching $_ which is defined. and you don't seem to be reading
in the data line after the header line.

CP> $header = $&;

don't use $&. make an explicit grab and use $1.

my( $header ) = />(.+)/ ;

CP> $bin = (split('[_-]', $header))[1];

split takes a regex so mark that with //. and why the convoluted code
there?

($bin) = $header =~ /-(\w+)-/ ;


CP> push @{$bins{$bin}}, $header;

uri
 
U

Uri Guttman

TA" == Tore Aursand said:
$bin = (split('[_-]', $header))[1];

TA> Maybe it's just me, but I don't see the string '[_-]' in the data you're
TA> reading? What are you _really_ trying to do? Match the part of the
TA> string _after_ the '[C/T]' string?

that is the same as /[_-]/. the first arg to split is always a regex,
even if it looks like a string. the special case of split ' ' is an
exception.

uri
 
A

Ala Qumsieh

Cognition said:
I am getting desried output for the following piece, but -w switch to perl
is reporting that 'if />.*/' in the code uses uninitialized value. The
input file follows. I also tried another combination of if statement, but
the error still persists. 'if /^(>.*)/' accessing the match from $1.


while(<FILE>) {
my ($header, ) = ();
next if /^$/;
chomp;

if (/>.*/) { # Use of uninitialized value here
$header = $&;
$bin = (split('[_-]', $header))[1];
push @{$bins{$bin}}, $header;
} else {
$fasta{$header} = $_;

This line causes your warnings. What happens if the line didn't match
your regexp? $header will be undef. It needs to be scoped outside the
while loop.

--Ala
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,236
Members
46,822
Latest member
israfaceZa

Latest Threads

Top