in reply to Re: Read fortran list output
in thread Read fortran list output

I'd use Scalar::Util::looks_like_number in addition:
#!/usr/bin/perl use warnings; use strict; use Data::Dumper; use Scalar::Util qw(looks_like_number); my $data = []; while (<DATA>) { chomp; if (/^(\w{1,2})$/) { push(@$data, [$1]); } elsif (looks_like_number($_)) { push(@{$$data[-1]}, $_); } } print Dumper($data); __DATA__ C -2.3242E-003 1.32423 0.34243E+002 -3.23134 MD 0.34243E+002 -3.23134

Replies are listed 'Best First'.
Re^3: Read fortran list output
by moritz (Cardinal) on Jul 30, 2008 at 10:53 UTC
    A nice addition, but you have to take care because not everything that is a number to Fortran is also a number to perl. For example Fortran has output format with a D instead of an E for the exponential.

    Which is why I lazily both recommended Fortran::Format and left the decision on what a number is as an exercise to the reader, who hopefully knows more details about the data format than I do.