I have data presented in a free format list, where the title begins on the first charater of the line and may be one or two characters, it is then followed by a series of numbers (one number per line, begins in the second column) that I need to read in as an array, before the next block begins. It isn't strictly delimited. The following is example input:
C
-2.3242E-003
1.32423
0.34243E+002
..etc...
-3.23134
H
more numbers
I need to get it as an array of arrays, i.e.
C -2.3242E-003 1.32423 0.34243E+002 ... -3.23134
H numbers
I don't necessarily know the length of the array and they aren't necessarily the same.
I've been trying to test on the first character of the line, but it seems to produce garbage.
Any help appreciated.
my $i=0;
while <$input>{
if (/^[A-Z]){
$AA[$i][0] = $_;
my $j=1;
}
else{
$AA[$i][$j] = $_;
$j++;
}
$i++;
}
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.