File I/O overwrite array variables?

Discussion in 'Perl Misc' started by jamesrwagner@gmail.com, Nov 14, 2007.

  1. Guest

    Hello:

    I was basically finding that after a block of code, an array I had
    called @localizations was still the same size, but each of the
    variables was now being overwritten by an empty string. What I found
    on closer inspection was that as I was reading in from the file with
    handle INPUT, each line was in turn being stored in the current place
    that it was on from the outer foreach loop, until upon termination
    when the final line is only a newline storing a n empty string in that
    place holder.

    The code below


    sub indexSequences {

    my $fold = shift;
    my $minSup = shift;

    my @localizations = ("cytoplasmic", "cytoplasmicmembrane",
    "extracellular",
    "outermembrane", "periplasmic");
    my %containsHash;

    foreach(@localizations) {
    my $localization = $_;
    open INPUT, "freseqs" . $_ . $fold . $minSup ;

    while(<INPUT>) {
    chomp;




    }

    foreach(@localizations) {
    my $alocalization = $_;
    print("This is the $alocalization $_\n");
    }
    }
    }
    Giving the following output:

    This is the localization
    This is the localization cytoplasmicmembrane
    This is the localization extracellular
    This is the localization outermembrane
    This is the localization periplasmic
    This is the localization
    This is the localization
    This is the localization extracellular
    This is the localization outermembrane
    This is the localization periplasmic
    This is the localization
    This is the localization
    This is the localization
    This is the localization outermembrane
    This is the localization periplasmic
    This is the localization
    This is the localization
    This is the localization
    This is the localization
    This is the localization periplasmic
    This is the localization
    This is the localization
    This is the localization
    This is the localization
    This is the localization


    Thus in turn the each element of the @localizations array is
    overwritten with an empty string. When I comment out the file I/O
    lines the problem goes away. (And the chomp makes no difference).

    What can be going on the reading in from a file is overwriting
    elements of an array?


    Thanks very much.
    , Nov 14, 2007
    #1
    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. John Harrison

    Re: file overwrite data manipulation

    John Harrison, Jun 26, 2003, in forum: C++
    Replies:
    2
    Views:
    5,946
    John Harrison
    Jun 27, 2003
  2. Chris Theis
    Replies:
    0
    Views:
    806
    Chris Theis
    Jun 26, 2003
  3. Someonekicked

    delete from a file, maybe overwrite!?

    Someonekicked, Oct 2, 2005, in forum: C++
    Replies:
    1
    Views:
    307
    lallous
    Oct 3, 2005
  4. ma740988
    Replies:
    1
    Views:
    467
    Kai-Uwe Bux
    Mar 6, 2006
  5. Replies:
    1
    Views:
    72
    Peter Makholm
    Nov 14, 2007
Loading...

Share This Page