Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This code is a part way point in the development of a tool to perform some directory and file management. At this stage it captures information required for the management from the user. The information gathered to controlled by a configuration file. This seems a generally usefull task so the code is offered here for other monks to make what use they wish of it.

The configuration files is comprised of lines containing a parameter name, and optional default value, and a label. For example:

_version_ "1_0" Version as it should appear in the project path (e.g. 1_0)

If the default string contains names of other parameters, the default value for the parameter will be generated at run time as the other parameters are updated.

The work of the task goes in sub CreateProject (which is an appropriate name for my initial task :).

use warnings; use strict; use Tk; =head Parse a configuration text file (TemplateValues.txt) to gather configu +ration parameters, defaults and labels required to perform some task then pre +sent a user interface built from the information in the configuration file to + capture user values for the parameters. =cut my $main = MainWindow->new (); if (! open configIn, "< TemplateValues.txt") { my $text = $main->Text (); $text->Insert ("Unable to open configuration file: $!"); $text->pack (); $main->Button (-text => "Quit", -command => sub {$main->destroy ()}) +->pack (); MainLoop (); exit (-1); } my %Parameters; while (<configIn>) { next if /^#/; #Skip comment lines chomp; next if ! length $_; my ($key, $default, $comment) = /^(\w+)\s(?:"(.*?)")?(.*)/; my $label = $main->Label (-text => $comment)->pack (); $Parameters {$key} = [ $main->Entry ( -validate => 'focusout', -validatecommand => sub {touch ($key);} )->pack (), $default ]; } touch (""); $main->Button (-text => "Cancel", -command => sub {$main->destroy ()}) +->pack (); $main->Button ( -text => "Create Project", -command => sub {tidyParams (); CreateProject (); $main->destroy (); +} )->pack (); MainLoop; sub CreateProject { #Note that %Parameters's values are now the user supplied strings print join "\n", map {$_ . " => " . $Parameters{$_}} keys %Parameters; } sub touch { my $key = shift; Entry: for (keys %Parameters) { next if defined $key and $key eq $_; my $repKey = $_; my $default = ${$Parameters {$repKey}}[1]; next if ! defined $default or ! length $default; #Don't edit while ($default =~ /(_[a-zA-Z0-9]+_)/) { next Entry if ! defined $Parameters {$1}; my $subStr = ${$Parameters {$1}}[0]->get (); $default =~ s/$1/$subStr/eg; } ${$Parameters{$repKey}}[0]->delete (0, 'end'); ${$Parameters{$repKey}}[0]->insert (0, $default) if length $default; } ${$Parameters{$key}}[1] = undef if defined $key and length $key; #Prev +ent auto default updates return 1; } sub tidyParams { touch (); for my $key (keys %Parameters) { next if ! length $key; next if ! defined $Parameters{$key}; $Parameters{$key} = ${$Parameters {$key}}[0]->get (); } }
_ExtensionFile_ File name for extension (excluding file extension) _ExtensionNameUI_ "_ExtensionFile_" Extension name as shown in UI _ExtensionPath_ "Extensions/_ExtensionFile_" Path from PCDevelop\Main +to folder containing project _MinVersion_ Minimum version required _ExtensionSlnFile_ "_ExtensionFile_" Name of solution file (excluding +file extension) _ExtensionType_ "Extension" Extension or Module _author_ Email name of primary extension author _version_ "1_0" Version as it should appear in the project path (e.g. +1_0) _ExtensionPath_ => Extensions/Telegraph _author_ => GrandFather@erewhon _ExtensionSlnFile_ => Telegraph _ExtensionType_ => Extension _version_ => 1_0 _ExtensionFile_ => Telegraph _MinVersion_ => 2.7 _ExtensionNameUI_ => Telegraph

Perl is Huffman encoded by design.

In reply to Utility to capture parameters and perform a task by GrandFather

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-03-29 15:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found