Lori713 has asked for the wisdom of the Perl Monks concerning the following question:
--Point to/Open the file YIKES.pl that contains 8000 lines of Perl code (see pseudo sample below). There may be zero, one, or more scalar variables per line of code.
--no "my" was used to initialize the variables since use strict wasn't used.
--Take every unique occurrence of a scalar variable and put it into an array(?). Not sure if I can be greedy and get it to only give me a list of unique items...
--Every scalar variable begins with a "$" symbol with an unknown number of alphanumeric characters or underscores, and can be terminated
by anything other than a letter, number or underscore.
--There are special Perl scalar variables like "$_", which would be nice to capture but not critical.
--Print the array to a file (text file would be okay), either separated with commas, or three "x"s, whatever/however.
I've looked at split and various regular expressions, but nothing's clicking. I also searched for regex, split, etc. on Perl monks for ideas. I'm especially having trouble getting a regex to recognize that there's more than one variable on a line, and terminating it before finding the next occurrence in that line. Or, getting a split to split on more than one character at a time.
I'd like to have a little .pl file that I can use to point at a file and get a list of the variables in that file. Any ideas on how best to accomplish this?
P.S. I'm really very new to Perl (see my initial post Sub-initiate needs help getting started), so a "dumbing down" re ideas/suggestions/explanations would not be considered bad on my part!
THANKS!
Lori
Pseudo sample YIKES.pl file (code doesn't work; modified to include certain characters/variations/possiblities):
print "<INPUT TYPE='HIDDEN' NAME='g_emplid' VALUE='$g_emplid'>" VALUE= +'$g_emplid7xyz'>"; print "<INPUT TYPE='HIDDEN' NAME='g_oprid' VALUE='$g_oprid)'>"; print "<INPUT TYPE='HIDDEN' NAME='g_LogonName' VALUE='$g_Logon3Name"'> +"; print "<INPUT TYPE='HIDDEN' NAME='g_projects' VALUE='$g_projects2['>"; print "<INPUT TYPE='HIDDEN' NAME='g_projects_valid' VALUE='$g_projects +_valid,'>"; print "<INPUT TYPE='HIDDEN' NAME='g_projects_valid' VALUE='%g_projects +_valid,'>";
update (broquaint): fixed formatting
|
|---|