If the distribution of white-space (including new-lines) is as chaotic as your sample suggests, something like this might be useful: slurp the whole file into a single scalar, as suggested in an earlier reply, then do a while loop over a regex match:
my $indata;
open( I, "<", "vrml.file" ) or die "vrml.file: $!";
{
local $/;
$indata = <>;
}
while ( $indata =~ /\[ # match open sq-bracket
((?:\s*\d+){3}) # match 3 numerics
, # match comma
((?:\s*\d+){3}) # match 3 more numerics
\] # match close sq-bracket
/gx )
{
my ( $x, $y ) = ( $1, $2 );
s/^\s+// for ( $x, $y );
my @x = split " ", $x;
my @y = split " ", $y;
# @x and @y each contain 3 numeric values
my $axis = "x";
for my $aref ( \@x, \@y ) {
print scalar @$aref, " elements in $axis array: @$aref\n";
$axis++;
}
}
The "x" modifier on the regex allows me to break up and comment the regex components for legibility. The "g" modifier will repeat the match throughout the data, and for every segment of data in the string (i.e. in the content of the file as a whole), I get one iteration of the while loop, with $1 and $2 set to the first and second sets of three digits.
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.