in reply to How to execute external script from CGI

One of the absolutely most offensive things I see wrt Perl is the practice of calling a Perl script from a Perl script.

Why? Other than just bad taste, you are unnecessarily burdening the operating system with the overhead of creating an additional perl interpreter, invoking all book keeping required for spawning and tracking child processes and memory. Oh, but it's just one extra process, you say! Well you keep doing that kind of thing and your CGI script grows in popularity and size - suddenly your server load is about 8,000 times what it should be. Do not laugh, I have seen it happen and continue to happen.

Turn loadCSV.pl into a modulino - it can be done in very few lines, even if it's a monolitic Perl script from 1974.

End result in your caller (not the best practice but will save you an OS process fork:
use FindBin ($Bin); require qq{$Bin/relative/../path/to/loadCSV.pl}; my $out = your::modulino->run( (qw/-L -Q/) ); print $out;
There are a million places to find informatin on modulinos, it's pretty much as simple as:
package your::modulino; use strict; use warnings; # Note: I know this is awful but it's better than what OP is doing now print __PACKAGE__->run(\@ARVG) if not caller; sub run { my $self = shift; local @ARGV = @_; # shove nearly all loadCVS.pl in here, getopt and all with ONE excep +tion # ... # convert all of your "print" statements such they create the string + you # were going to print, then: return $formerly_printed_stuff; } 1;
The above is dirty, but better what you're doing. And it provides the basis for really creating a well done modulino. Or better yet, an actual Perl module where the CLI version becomes a 3 line script calling the dern module you just peared off.

Replies are listed 'Best First'.
Re^2: How to execute external script from CGI
by vskatusa (Acolyte) on May 22, 2020 at 13:45 UTC
    Hi I have already a module for this...I did not show the whole framework. Thanks for commenting
      We can only go by what you post. From your other posts I can assume you're coming here for wisdom, and I am happy to oblige. If you have updated code, post it. Mostly what people what to see here is that you're learning - or at least trying. We're all here to learn. That's why I am here.
Re^2: How to execute external script from CGI
by Anonymous Monk on May 22, 2020 at 09:24 UTC
      So I guess a modulino written in Moo is triple evil? xD

      It's a handy tool on the way to full modularization. There's nothing gimmicky about it unless you consider 5% of the work and 95% of the benefit of full modularization a con.

      In a legacy environment, this can mean the difference between $20,000 worth of new hardware versus about 1 hour of developer time. I've scene both scenarios play out, with the former still required quite a bit of refactor.

      A reply falls below the community's threshold of quality. You may see it by logging in.