in reply to Re: Problems calling a second perl script from the first
in thread Problems calling a second perl script from the first

Hello kennethk,

frankly, I copied the routine for uploading a file (http://aktuell.de.selfhtml.org/artikel/cgiperl/file-upload/, a german HTML "learning" site) as I didn't had any clue how to do it in perl. I think it had something to do with uploading and converting the file.

If I modifie the code like that:

$wfile = $cgi->param("toping"); + #Upload Teil des Scripts $wfname = 'toping'; #Upload Teil des Sc +ripts open (my $DAT,">", "/home/deruytja/webserver/rifucgi/temp_ul/$wfname") + or die 'Error processing file INPUT: ',$!; #Upload Teil +des Scripts print $DAT $wfile;

I'll only get the filename written to my temp file (the "toping" one)

I've modified the bareword filehandles already (I know barewords are a bad practice and I can't remeber why I did it this way).

I'm mostly using google and the "trial and error" method for learning. Maybe you could point me to my problems? Especially the open arguments and the unescaped text.

I'm not a skilled programmer as I've learned more in the direction of hardware and planning

Replies are listed 'Best First'.
Re^3: Problems calling a second perl script from the first
by kennethk (Abbot) on Apr 13, 2015 at 16:07 UTC
    So $cgi->param("toping") contains the target file name. So that means you need to open the target file and input it. Mimicking the behavior of the original source material, you might do something like:
    sub UPLOAD { $wfile = $cgi->param("toping"); open(my $wfin, '<', $wfile) or die "Error opening $wfile: $!"; $wfname = 'toping'; open (my $datin,">", "/home/deruytja/webserver/rifucgi/temp_ul/$wf +name") or die 'Error processing file INPUT: ',$!; binmode $wfin; binmode $datin; while (read $wfin, my($data), 1024) { print $datin $data } #Upload Teil des Scripts }
    With regard to reading material, there's a fair amount you could learn from Ovid's CGI Course - Resurrected and Updated! about good practice. He discusses taint and other security issues. It's worth noting that people generally don't use CGI directly any more. Specifically, the docs for CGI itself say
    The rationale for this decision is that CGI.pm is no longer considered good practice for developing web applications, including quick prototyping and small web scripts. There are far better, cleaner, quicker, easier, safer, more scalable, more extensible, more modern alternatives available at this point in time.
    Modules like Template::Toolkit (which is rolled into frameworks like Mojolicious, Dancer2 and Catalyst) allow for clean separation between your logic and layout, and can defaultly handle the character escaping.

    #11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

      I've tried it now with the $cgi->upload('toping') version and also with your version, still no luck.

      To clarify what the script should do (and normally does very well), I'll explain a bit: The whole script is just a multiping utility where a user is allowed to upload a file containing IP adresses and labels, so I need to write an upload routine, process the uploaded file and ping the devices inside.

      As we've got another project I needed to take a look at the GD::Graph module. To get to know the module I wanted to implement it to the existing ping utility.

      In my understanding, the whole problem is that the subscript for plotting the graph needs to "check" all the variables in the "multiping-script" (Which I don't understand as it only uses the "our" variables) and doesn't like the empty "filehandle" with which I upload the file at first

      If the "multiping-script" is started at first (via the HTML page) the "filehandle" is filled, as their is user input, the second time the "multiping-script" is called (via the graph script) the "filehandle" is empty (which is correct as their are no parameters given)

      Is there a way to bind these 2 scripts together without the check on the variables which aren't needed?

      Tomorrow I'll take a look at the Template::Toolkit and maybe change over to this one.

        normally, in HTML, images (such as your graph) are requested separately from the "text", so it would have to be a different script, and the parameters have to come in via URL parameters, which mandates parameter checking, because anyone could call the "image script" by hand.

        It is possible to incorporate images directly with <img src="data:... (see

        So you could call your graph generator directly as a subroutine (with already checked parameters). Of course, your subroutine would have to (base64) encode the image.