#!/usr/bin/perl -w # # Scenario: Given lines of f77 code, # parse out the comma delimited var+iables. # use Data::Dumper; # A real application will read in f77 source, # this is just a sample. my $string = "real*8 Eparams(0:maxParam),". "Emvm(0:3),". "YourArray(12,(j,k),m),". "MyArray(row,col)"; my $open = 0; my $close = 0; my @fields = (); my $a; # --- get rid or 'real*8' $string =~ /(\w+)(\*[0-9]*)?/gc; # --- keep looping until entire string is processed while (not $string =~ /\G\z/gc) { # --- get variable name if ((not $open) and ($string =~ /\G(?:\s*|,)(\w+)/gc)) { push @fields, $1; print "$1\t"; } # --- find opening brackets, and keep track of level elsif ($string =~ /\G([^\)]*\()/gc) { $a = $1; $open++; } # --- find closing brackets, and print info elsif ($open and ($string =~/\G\s*([^\(]*\))/gc)) { print "-> $a$1\n"; $open--; } } #print "Fields:",Dumper(\@fields); exit(0);