Hello folks, at the moment I'm encountering a problem which I don't understand fully. I've written a web based ping script as a project, now i want to integrate a Graph (Via GD::Graph::bars) trough a second script (as I don't want a stored image on the server). The problem is now, I'll always get the error "multipinggraph.pl: Can't use an undefined value as a symbol reference at multiping.pl line 138." from the second script. I think it has something to do with the variable declaration but I've got no idea how to solve the problem.

The first script, which gets called from the html-page is this: multiping.pl
#! /usr/bin/perl use strict; use warnings; use FindBin qw ($Bin); use Net::Ping; use CGI; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use Time::HiRes; use Time::Piece; our $date = Time::Piece->new->strftime('%Y-%d-%m_%H-%M-%S'); #Aktue +lles Datum open (STDERR, '>/home/deruytja/webserver/rifucgi/logs/'.$date.'multipi +ng_error.log'); #Redirecting Standart Error to file my $cgi = new CGI; my $dateiname = $cgi->param('dateiname'); my ($data, $file, $out_file, $wfname, $wfile, $i, $dur,$age, $key, $typ, $val, $p1, $p2, $p3, $ip, $out, $anzahl, $start, $ende, @label, @dauer, %devices, @check); our (@graphdata); if (!length($dateiname) == 0) { $out_file = ("$dateiname\_$date.csv") or die 'Error processing + file: ',$!; } else { $out_file = ("ping_$date.csv") or die 'Error processing file: +',$!; } my $ping1 = Net::Ping->new("tcp", 1); my $ping2 = Net::Ping->new("tcp", 1); my $ping3 = Net::Ping->new("tcp", 1); $ping1->port_number("80"); $ping2->port_number("5432"); $ping3->port_number("301"); $ping1->hires(); $ping2->hires(); $ping3->hires(); my $outpath = '/home/deruytja/webserver/output/multiping/'; open ($out, '>', $outpath.$out_file) or die 'Error processing file: ', +$!; $out->autoflush(1); &UPLOAD; open (INPUT,"</home/deruytja/webserver/rifucgi/temp_ul/$wfname"); &READIN; close INPUT; $anzahl = keys %devices; $i=0; $start = Time::HiRes::time(); foreach (keys %devices) { ($p1, $dur, $ip) = $ping1->ping($devices{$_}); $typ='SIAE'; if (!$p1 == 1) { ($p2, $dur, $ip) = $ping2->ping($devices{$_}); $typ='Huawei'; if (!$p2 == 1) { ($p3, $dur, $ip) = $ping3->ping($devices{$_}); $typ='Siemens'; } if (!$p3 == 1){$typ='Unknown'} } if ($p1 == 1 or $p2 == 1 or $p3 == 1) { $dur = sprintf("%.2f", 1000 * $dur); push (@label,$_); #LinkID ins erste Array push (@dauer,$dur); #duration ins 2te Array $check[$i] = 'ACTIVE;'.$_.';'.$typ.';'.$devices{$_}.';'.$d +ur.'ms'."\n"; } else { push (@label,$_); #LinkID ins erste Array push (@dauer,'0'); #duration ins 2te Array $check[$i] = 'OFFLINE;'.$_.';'.$typ.';'.$devices{$_}."\n"; }; $ping1->close(); $ping2->close(); $ping3->close(); $i++; } $ende = Time::HiRes::time(); push @check, 'Ausführdauer: '.sprintf("%.2f",($ende-$start)).'s'; print $out 'Ping_result;Link_ID;Device_Type;IP;Ping_time'."\n"; foreach (@check) { print $out "$_"; }; close $out; @graphdata = ([@label],[@dauer]); ########################OUTPUT print $cgi->header, $cgi->start_html('Pingergebnis'), $cgi->h1('Ergebnis des Pings'), $cgi->br(); print "<tr>\n"; print $check[-1]; print "</tr>\n"; print $cgi->br(); print "<img src=/rifucgi/multipinggraph.pl>"; print $cgi->br(), $cgi->br(), $cgi->a({-href => "/output/multiping/$out_file"},'Auswertung') +, $cgi->br(), $cgi->a({-href => '../ping.html'},'Back to Paradise'), $cgi->end_html; ########################/OUTPUT sub READIN { while (<INPUT>) #Schleifenstart zum Einlesen der Werte { for ( "\r\n") {$/="\r\n"} chomp; #Abschneiden des INPUT_RECORD_SEPARATORS ($val, $key) = split /;/; #Teilen der Werte nach $val(ue) und $ +key (BGTR ID) if (exists $devices{$key}) {next;} else {$devices{$key} = $val;} } } sub UPLOAD { $wfile = $cgi->param("toping"); $wfname = 'toping'; open (DAT,">/home/deruytja/webserver/rifucgi/temp_ul/$wfname") or die +'Error processing file INPUT: ',$!; binmode $wfile; + binmode DAT; + while (read $wfile, $data, 1024) + { + print DAT $data + } #Upload Teil des Scripts close DAT; }
the second script, which gets called in the cgi print piece of the code, multipinggraph.pl:
#! /usr/bin/perl #use strict; use warnings; use GD::Graph::bars; require "multiping.pl"; our (@graphdata, $date); my ($mygraph,$graphimage); open (STDERR, '>/home/deruytja/webserver/rifucgi/logs/'.$date.'multipi +nggraph_error.log'); #Redirecting Standart Error to file $mygraph = GD::Graph::bars->new(500, 300); $mygraph->set( x_label => 'Link', y_label => 'Antwortzeit', title => 'Antwortzeiten der Links', ) or warn $mygraph->error; $graphimage = $mygraph->plot(\@graphdata); print "Content-type: image/png\n\n"; binmode STDOUT; print $graphimage->png;
I (think) I know the code isn't perfect, but works well (It's only for a small amount of users). Thanks for the help!

In reply to Problems calling a second perl script from the first by deruytja

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.