use of uninitialised value

Discussion in 'Perl Misc' started by Cognition Peon, Apr 15, 2004.

  1. 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




    --
    echo | perl -pe 'y/a-z/n-za-m/'

    Q: How many CPU's does it take to execute a job?
    A: Four. Three to hold it down, and one to rip its head off.
    -------------------------------------
    Printed using 100% recycled electrons
     
    Cognition Peon, Apr 15, 2004
    #1
    1. Advertising

  2. 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
    >
    >
    >
    >
    >


    --
    echo | perl -pe 'y/a-z/n-za-m/'

    Life is a bridge, enjoy while crossing but don't build
    a castle on it. - Upanishads
    -------------------------------------
    Printed using 100% recycled electrons
     
    Cognition Peon, Apr 15, 2004
    #2
    1. Advertising

  3. Cognition Peon

    Tore Aursand Guest

    On Wed, 14 Apr 2004 20:39:10 -0700, Cognition Peon wrote:
    > 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.

    > chomp;


    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
    }
    }


    --
    Tore Aursand <>
    "The purpose of all war is ultimately peace." -- Saint Augustine
     
    Tore Aursand, Apr 15, 2004
    #3
  4. Cognition Peon

    Uri Guttman Guest

    >>>>> "CP" == Cognition Peon <> writes:

    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

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Apr 15, 2004
    #4
  5. Cognition Peon

    Uri Guttman Guest

    >>>>> "TA" == Tore Aursand <> writes:

    >> $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

    --
    Uri Guttman ------ -------- http://www.stemsystems.com
    --Perl Consulting, Stem Development, Systems Architecture, Design and Coding-
    Search or Offer Perl Jobs ---------------------------- http://jobs.perl.org
     
    Uri Guttman, Apr 15, 2004
    #5
  6. Cognition Peon

    Ala Qumsieh Guest

    Cognition Peon wrote:
    > 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
     
    Ala Qumsieh, Apr 15, 2004
    #6
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Andy Fish
    Replies:
    7
    Views:
    554
    David Carlisle
    Jan 10, 2005
  2. Len
    Replies:
    3
    Views:
    193
  3. Jess
    Replies:
    2
    Views:
    170
  4. Justin C
    Replies:
    6
    Views:
    142
    Justin C
    Jul 23, 2010
  5. Mark

    uninitialised value & valgrind

    Mark, Jun 26, 2012, in forum: C Programming
    Replies:
    4
    Views:
    1,127
    Johann Klammer
    Jun 27, 2012
Loading...

Share This Page