lmtaylor has asked for the wisdom of the Perl Monks concerning the following question:
Hello. I'm trying to take a very large array and re-format it. The initial array looks something like this:
>123
ABD
CEF
GHI
>456
JKL
MNO
>789
That's obviously simplified, but that's the idea. I want to join the elements between the two lines that begin with '>' and then get rid of the lines that begin with the '>', so my final array looks something like this:
ABDCEFGHI
JKLMNO
Here is the code I've written to do it. My problem is, every time I run it, I get a million errors that all say "Use of uninitialized value in substr at line 19." But I can't figure out what value it's talking about.
#!/usr/bin/perl -w my @contigfile = (">37","ABC","DEF","GHI","JKL","MNO","PQR","STU","VWX +","YZ",">38"); my $element1 = 0; my $element2 = 0; # print @contigfile; # print substr($contigfile[$element1],0,1); # print $contigfile[$element1]; while ($contigfile[$element1]){ if (substr($contigfile[$element1], 0, 1) eq '>'){ do { ++$element2; } until (substr($contigfile[$element2], 0, 1) eq '>'); $new = join('',@contigfile[($element1 + 1)..($element2 - 1)]); splice @contigfile, $element1, $element2, "$new"; ++$element1; $element2 = $element1; } } print @contigfile; exit;
I wrote this code to test my method before implementing it in my real program, which will take the array in from an input file. Only I can't figure out what this error is talking about. The commented out print commands work just fine. Does anyone see something that I'm missing?
Thank you so much for your help!
- Lisa
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Uninitialized value in substr command
by hippo (Archbishop) on Aug 20, 2014 at 21:28 UTC | |
by lmtaylor (Novice) on Aug 21, 2014 at 17:42 UTC | |
by Laurent_R (Canon) on Aug 21, 2014 at 18:01 UTC | |
|
Re: Uninitialized value in substr command
by Laurent_R (Canon) on Aug 20, 2014 at 21:27 UTC | |
by Lotus1 (Vicar) on Aug 21, 2014 at 14:06 UTC | |
by lmtaylor (Novice) on Aug 21, 2014 at 17:44 UTC | |
|
Re: Uninitialized value in substr command
by Anonymous Monk on Aug 20, 2014 at 21:53 UTC | |
|
Re: Uninitialized value in substr command
by Anonymous Monk on Aug 20, 2014 at 23:04 UTC | |
|
Re: Uninitialized value in substr command
by choroba (Cardinal) on Aug 21, 2014 at 07:48 UTC |