Hello again everybody, I'm currently working on a project parsing Awesome Window Manager's Lua configuration files for important configuration and theme settings, displaying the desired settings, and eventually allowing the user to modify settings by editing the files.

I've been able to gather the settings and place them in hashes based on the type of setting. Now I am trying to allow the user to pick a single group or a group of groups based on their input. I plan on giving viewTheme() the ability to split comma separated input and return the split elements in the same manner as I've returned all the groups. It may sound silly, but these are the most complex data structures I've dealt with thus far in my learning and I feel like my functions are starting to get bloated (printSettings in particular) and confusing.

The code works, but I'd like to clean these functions up before adding to them. Is the bloated feeling due to my being unaccustomed to seeing code with these more complex data structures, or is my inexperience in writing code at this level causing me to write bloated inefficient code? Is this code a viable solution for what I am trying to accomplish at this point, or can you suggest changes I should make before moving forward?

Applicable functions:

sub printSettings { my @groups = shift; foreach my $table (@groups) { foreach my $info (@$table) { my $cnt = 1; print "=" x 60, "\n"; print " $info->[0]", " " x 20, "\n"; print "=" x 60, "\n"; foreach my $key (sort keys %{$info->[1]}) { printf "%5s. %-25s %-5s $info->[1]{$key}\n", $cnt, $ +key, "=>"; $cnt++; } } } } sub viewTheme { #print "[(a)ll, (b)ase, (m)enu, tag(l)ist, (o)other]{Enter to quit +}: "; #chomp (my $item = <STDIN>); my $item = shift; my $base = ["Base Elements", \%theme_base]; my $taglist = ["Taglist Elements", \%theme_taglist]; my $menu = ["Menu Elements", \%theme_menu]; my $other = ["Other Elements", \%theme_other]; return unless ($item); return [$base] if ($item =~ /^\s*(?:b|base)\s*$/i); return [$taglist] if ($item =~ /^\s*(?:l|taglist)\s*$/i); return [$menu] if ($item =~ /^\s*(?:m|menu)\s*$/i); return [$other] if ($item =~ /^\s*(?:o|other)\s*$/i); if ($item =~ /^\s*(?:a|all)\s*$/i) { return [$base, $taglist, $menu, $other]; } say "Invalid Entry: $item\n"; viewTheme(); }

If I call printSettings(viewTheme("all")) it outputs:

============================================================ Base Elements ============================================================ 1. theme.bg_focus => #000000 2. theme.bg_minimize => #ff0000 3. theme.bg_normal => #000000 4. theme.bg_urgent => #ffffff 5. theme.border_focus => #55B043 6. theme.border_marked => #91231c 7. theme.border_normal => #000000 8. theme.border_width => 2 9. theme.fg_focus => #55B043 10. theme.fg_minimize => #ffffff 11. theme.fg_normal => #ffffff 12. theme.fg_urgent => #ffffff ============================================================ Taglist Elements ============================================================ 1. theme.taglist_bg_focus => #000000 2. theme.taglist_bg_normal => #000000 3. theme.taglist_fg_focus => #55B043 4. theme.taglist_fg_normal => #000000 ============================================================ Menu Elements ============================================================ 1. theme.menu_bg_focus => #55B043 2. theme.menu_bg_normal => #000000 3. theme.menu_border_color => #000000 4. theme.menu_border_width => 5 5. theme.menu_fg_focus => #000000 6. theme.menu_fg_normal => #55B043 7. theme.menu_height => 15 8. theme.menu_width => 150 ============================================================ Other Elements ============================================================ 1. theme.font => sans-serif 8: bold 2. theme.wallpaper => /usr/share/awesome/themes/wal +lpapers/ireck.png

Calling an individual group outputs the respective group similarly. Thank you for any input/suggestions


In reply to Awesome WM config: Lua Source Parse by marquezc329

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.