I want a list of all the scalar variables contained in my YIKES.pl file. Some notes/steps/ideas I've had so far:

--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


In reply to Extract variables from file (split? regex? backflip?) by Lori713

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.