laziness, impatience, and hubris | |
PerlMonks |
Re: Defining directory/Datas the perl script should work withby kcott (Archbishop) |
on Oct 21, 2021 at 23:29 UTC ( [id://11137870]=note: print w/replies, xml ) | Need Help?? |
G'day perlnewbie, Welcome to the Monastery. "I think there a lot of syntax errors" Yes, there are but these seem to have been addressed. I was concerned with this block of code:
I may be wrong, but it looks like you were planning to, or at least thinking about, using symbolic references. This is generally considered to be a bad move and I would recommend that you steer clear of them until you're more experienced; even then, think very carefully before using them. Follow the link I provided. Note that they can easily result in coding errors or simply confusing code. Your lexical (my) variables do not work with this mechanism. Perhaps inadvertently, you've expressly forbidden your code from using them (with use strict;): it will abort compilation if you attempt to do it. The strict pragma restricts their usage for a very good reason. "In my script I want the outputimage to be saved in an other folder. Could anyone help me with this?" I would set up default paths for your input and output directories; then allow users to specify alternatives via options. I would include thorough checking of all input from options and clean any tainted data (see perlsec for more about that). Unsurprisingly, I have neither the bet program nor any MRI data. For testing, I set up an extremely minimal script to replace bet:
and two directories, whole_head and just_brain, for input and output, respectively. The former has four tiny files, the latter starts empty:
Here's the code (pm_11137850_system.pl):
You'll obviously need to make a number of changes for your own needs: the paths with '/home/ken/...'; perhaps s/ZOMBIE/BETCMD/; the regexes for checking user input; and so on. Do note that the system() function takes a list. You'll probably want to expand my simplistic one line
to include some error checking, handling and reporting. And, obviously, the list of arguments will need to be changed. Take a look at Getopt::Long to change or extend options. Also, the "Documentation and help texts" section, along with Pod::Usage, for an improved user experience. Here's a sample run showing that there's no tainting:
Here's another showing what would probably be more normal usage:
Here's some example error messages:
— Ken
In Section
Seekers of Perl Wisdom
|
|