undef my %functions;
What's the point of using an explicite undef here? What's wrong with my %functions;?
my $regex = "\$file =~ s/\\\$$variable/$path/g;"; eval "$regex";
I don't get this. Why not just $file =~ s/\$$variable/$path/g;, or, if you're worried the substitution has a fatal syntax: eval {$file =~ s/\$$variable/$path/g;}? But you aren't checking the result of the eval, so you must be confident that it won't fail.
open FH2, "<$file";
Remember what one of the creators of Unix (Thompson?) said: not being able to open a file is not exceptional. Always check if opening a file succeeded.
if(/^[ \t]*source +([\w\-\/\.\_\$]+)/)
Hmmm. So, I can have tabs before the source keyword, but not after them? And I cannot surround the filenames with quotes? Or have non-word characters other than '-', '/', '.', '_' or '$' in them?
if($check_if_bash == 1 && $line_number == 1 && ! /bash/) { return }
A bash script doesn't have to start with a line saying "bash". Just like a Perl program doesn't have to start with a line saying "perl". And even if such a script starts with a she-bang line, it may says #!/usr/bin/sh, where /usr/bin/sh and /usr/bin/bash are links to the same file.
# Count comments and empty lines elsif(/(\%\%.*\%\%)/) {
What makes you think that %% ... %% on a single line is a comment block in bash? My bash manual mentions various meanings for %% depending on context, but none of them have anything to do with comments.

You also seem to assume bash programs use only newlines as statement separators, and all newlines separate statements. Neither statement is true.

You don't seem to deal with any of the many quoting and grouping mechanisms of a bash program. Nor does your program seem to be able to deal with here documents.

There's quite some duplication of code between 'match' and 'get_sources', but there are also differences. It's totally unclear to me why there need to be any differences.

It looks to me there's no guards against infinite recursion. If file 'A' contains source A, then your program will never stop by itself.


In reply to Re: Bash Parser by JavaFan
in thread Bash Parser by mickep76

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.