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

$wfile = $cgi->param("toping"); $wfname = 'toping'; open (DAT,">/home/deruytja/webserver/rifucgi/temp_ul/$wfname") or die +'Error processing file INPUT: ',$!; binmode $wfile;
You are getting this error because you are treating an ordinary scalar $wfile like an indirect file handle. What are you trying to do with this? Why can't you just say
$wfile = $cgi->param("toping"); open (my $dat,">", "/home/deruytja/webserver/rifucgi/temp_ul/$wfname") + or die 'Error processing file DAT: ',$!; print $dat $wfile;
As a side note, there are a number of things you've done here which are poor practice from a modern web perspective, including 2 argument opens, bareword filehandles, and parroting unescaped text back to the browser. What resources are you using to learn Perl web scripting?

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

Replies are listed 'Best First'.
Re^2: Problems calling a second perl script from the first
by deruytja (Novice) on Apr 13, 2015 at 15:30 UTC
    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

      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.