Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

Re^2: Defining directory/Datas the perl script should work with

by perlnewbie (Novice)
on Oct 22, 2021 at 08:06 UTC ( [id://11137874]=note: print w/replies, xml ) Need Help??


in reply to Re: Defining directory/Datas the perl script should work with
in thread Defining directory/Datas the perl script should work with

Thank you very much!! But I think I still have some questions to this code:  BEGIN { delete @ENV{qw{PATH IFS CDPATH ENV BASH_ENV}} } --> why should I use this? I haven't used it in former scripts... Moreover, I don't understand why I need the sub_ after I run the system? And somehow when I try to run the modified script (with my directories etc) an error " "use" not allowed in expression at script.pl line 17, at end of line" " is given out. So do I need the use  GetOptions::LONG at all? Thanks again. Best Regards, M

Replies are listed 'Best First'.
Re^3: Defining directory/Datas the perl script should work with
by bliako (Monsignor) on Oct 22, 2021 at 10:04 UTC

    kcott's script is a good way to start this project.

    So do I need the use  GetOptions::LONG at all?

    I would encourage you to use it (note that it's Getopt::Long click to see examples of use) as it offers the best way of dealing with user-supplied parameters at runtime instead of hardcoding those in the script. It's even better than a configuration file read when your script starts because it can allow specifying both a configuration file and extra command-line options which can override options in the configuration file. E.g. myprog --config a/b/c  --iterations 100 --bin-dir /usr/bin/protokoll2. So, it will help you start this project from a solid foundation. I guess extract-brain needs a hell of parameter tweaking depending on protocol, resolution, quality. That's a good way to deal with that complexity. Next step would be to decide on a configuration-file format, plenty of options in Perl's CPAN repository of modules. Additionally, you may want to run your script with different configurations and parameters in parallel to assess their efficacy efficiently. Again, using configuration files and command-line parameters will help immensely.

    Also, note that you can specify subs (functions) anywhere in your Perl script and not necessarily before calling them(re: I don't understand why I need the sub_ after I run the system?). I personally define all my subs at the end of a script, leaving the beginning for the "main" section.

    bw, bliako

      ++ Thanks, bliako.

      There were no responses to the OP's follow-up question when I started to compose mine; however, after I posted it, I saw that you had already replied.

      I can't see any conflicts between our two posts; in some places there's complementary information.

      — Ken

Re^3: Defining directory/Datas the perl script should work with
by kcott (Archbishop) on Oct 22, 2021 at 11:01 UTC
    "I think I still have some questions to this code"

    I'm pleased to see that you are not a cargo cult programmer. See "Cargo cult programming" if you are unfamiliar with that term.

    I provided a variety of links which you should follow. The one to perlsec explains the inclusion of the BEGIN block. If you're stumped by the meaning of the BEGIN itself, read "perlmod: BEGIN, UNITCHECK, CHECK, INIT and END". You may also want to look at: the delete() function; "perldata: Slices"; "perlvar: %ENV"; and, perlop for qw (search the page: qw appears in a number of places). You can also try commenting out the BEGIN line, running with the taint checking I showed (perl -T ...); then checking the messages output.

    I'm not too sure about "sub_" as it doesn't appear in my code (perhaps a typo in your code). There are two subroutine declarations of the form sub _name {...}. These are called earlier in the code with _name(...). Prefixing a subroutine name with an underscore is an informal way of indicating it is intended to be private (used by the code itself, but not directly called by the user of the code): this is fairly common practice and you're likely to encounter it in many places. Also look at perlsub; in particular, the To declare subroutines: and To call subroutines: sections of its SYNOPSIS.

    If you have GetOptions::LONG in your code, it's a fairly major typo: the first 'O' should be lowercase; there's no 'ions'; and, the last part is capitalised, not all uppercase. Case and spelling matter. I wrote: "use Getopt::Long;" at line 14 and "GetOptions(...);" at line 17. You may have somehow confused those two lines, omitted a semicolon near those lines, or something else: without seeing exactly what code you wrote, I'm completely guessing.

    That covers everything you enquired about. If more questions arise, feel free to ask.

    — Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11137874]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found