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

hi,

i have a litle problem with this peace of code:

use Bio::Trace::ABIF; ... my $abif = Bio::Trace::ABIF->new(); ... foreach my $abifiles (@{$maindata->[1]}){ $abif->open_abif($abifiles); print "$abifiles\n"; my $sequence = $abif->sequence(); print "$sequence\n\n"; ... and so on }
the problem is that for each argument in my array @{$maindata->1} it prints $abifiles and $sequence variable but when it comes to the last value of the array it just prints variable $abifiles but it doesn't want to return sequences from $abif->sequence() so the $sequence variable stays empty. and only for the last iteration of the foreach loop $sequence is empty. is there a way to solve (flush) this problem or go around it.

it's like he can't open the last $abifiles. i tried to change the order of the arguments in the array and still the last variable is the problem

thanx

Replies are listed 'Best First'.
Re: foreach loop problem
by ikegami (Patriarch) on Jan 10, 2009 at 22:24 UTC

    There's absolutely no reason to believe that foreach has anything to do with this. I suspect the last $abifiles doesn't contains what you think it does. Perhaps there's trailing white space or a newline. Temporarily add the following inside the loop:

    use Data::Dumper; local $Data::Dumper::Useqq = 1; local $Data::Dumper::Terse = 1; local $Data::Dumper::Indent = 0; print("$abifiles = ", Dumper($abifiles), "\n");

    You should also change:

    $abif->open_abif($abifiles);

    to

    $abif->open_abif($abifiles) or die("Can't open or read file \"$abifiles\". " ." Possible error: $!\n");

    From looking at the source, $! is accurate if no other error messages is displayed. (It can even be accurate if another error message is displayed.)

      thank you, i totally overlooked this in my array:
      './F4a_0149_2008-01-25/67C092008-01-25.ab1 '
      which was easily solved by chomp($_); ++ for the replay

      thanx

      too tired !!