I am trying to extract all variables in a list from some f77
declarations. Fortran can have nasty nested levels of parenthesis which is confusing. I tried a naive split but that did not work. Here is a simple attempt.
#!/usr/bin/perl -w
#
# Scenario: Given lines of f77 code, parse out the comma delimited var
+iables.
#
use Data::Dumper;
use Text::Balanced qw(extract_delimited extract_multiple extract_varia
+ble);
# A real application will read in f77 source, this is just a sample.
my $string = "real*8 Eparams(0:maxParam),Emvm(0:3),MyArray(row,col),Yo
+urArray(12,(j,k),m)";
#
my @fields = extract_multiple($string,
[ sub { extract_delimited($_[0],q{\,}) } ], undef, 1);
print "Fields:",Dumper(\@fields);
exit(0);
After I get the individual variables, with their array dimensions, I will use the information for generating new code.
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.