in reply to Re^2: RFC: newscript.pl , my very first script!
in thread RFC: newscript.pl , my very first script!
That's a very good point. Is it safer to make checks for everything the user can input or that has no influence in the security of the program?
What I need to do:
- add possibility for the user to cluster frequently used modules/libraries with tags (thinking about using hashes)
- make use of environment variable to determine which is the default editor and make use of it, instead of assuming emacs. (not sure how to do that yet)
thanks for your suggestions :)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: RFC: newscript.pl , my very first script!
by afoken (Chancellor) on Jul 26, 2015 at 12:36 UTC | |
A hash of hash references looks like a good idea. Use arrays in the third level to allow more than one library per tag:
Note that you could use pseudo-tags to define a file header, default libraries, and anything else that you may need. Think about getopt for entering tags. Use Getopt::Long. How should the command line look like?
I prefer "don't make me think" and "don't make me type". Implicit language is not hard, just guess it from the file extension: .pl and .pm for Perl, .sh and .bash for bash, and so on. Without a file extension, require a language argument. Use a hash for default mappings:
Library tags would be different for different languages, e.g. moose would make no sense for bash at all, so it should result in an error message. When you use Getopt::Long for the first form, you would check the library tags returned from GetOptions(). The language is known at this point, either from a --lang option, or from the file extension. When you use a flag argument for each library tag, you need to know all allowed tags before calling GetOptions(). For that, you have two options:
Legal values for the language are simply available as keys %langTags. Legal values for the library tags are available as keys %{$langTags{$language}}. A little bit of code is required to get a list of all library tags:
Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] |
|
Re^4: RFC: newscript.pl , my very first script!
by afoken (Chancellor) on Jul 26, 2015 at 11:24 UTC | |
Commonly, the EDITOR or VISUAL environment variables specify which editor executable to use. If both are unset or empty, use some arbitary fallback. The debian people use a bunch of symlinks to specify a default editor in /usr/bin/editor. The two environment variables may contain only the name, not the absolute path of the editor. So you also have to search $ENV{'PATH'}. Different editors have different command line options. The only thing that you can rely on is that the editor will accept a single argument containing a filename to be edited. In other words: no extra command line options as long as you allow having different editors.
Alexander
-- Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-) | [reply] [d/l] [select] |
|
Re^4: RFC: newscript.pl , my very first script!
by Darfoune (Novice) on Jul 26, 2015 at 18:44 UTC | |
Well thank you very much, you guys really know what you're doing. That's definitely something I look forward writing. Now I first have to go again over map and make sure I get it right, I'll have to try getops as well since I haven't yet, and I just started this morning the chapter on references in intermediate perl so hopefully soon enough I'll rewrite newscript with your suggestions in. I'll keep you updated, thanks! :) | [reply] |