arguelje has asked for the wisdom of the Perl Monks concerning the following question:

I have created an html page in which I ask the user to input a text file containing a column of numbers that I will use to create a histogram, also I ask the user to enter the desire numbers of bins. After the user has enter the information, I redirect and past the information using the post method to my perl cgi code that will create the histogram.

The part of my code that is suppossed to print the histogram is:

my $format = $my_graph->export_format; print header("image/$format"); binmode STDOUT; print $my_graph->plot(\@data)->$format();

I know that the code is performing very well the task on creating the histogram, but I have not able to print the histogram, but the server is giving me the following error, and I do not how to fix it:

Can't call method "gif" on an undefined value at C:/Apache/Apache2/cgi +-bin/histogram.pl line 86, <fh00001miniproject620.txt> line 113.

I did setup the server myself, I am using apache latest version, in an windows xp laptop. Also, I am using the latest version of ActivePerl from Active State.

If someone can help, I will really appreciate.

Jose.

Edit: g0n - code tags

Replies are listed 'Best First'.
Re: Creating a Histogram
by samizdat (Vicar) on Apr 19, 2006 at 12:19 UTC
    I woulds suggest that you first save the image on your filesystem, and verify that it is indeed correct.

    Then, and only then, work on an inline HTML page. :D

    Don Wilde
    "There's more than one level to any answer."
Re: Creating a Histogram
by cdarke (Prior) on Apr 19, 2006 at 13:34 UTC
    I can't be certain, but I suspect the problem is in the last print statement you show.
    print $my_graph->plot(\@data)->$format();
    The plot function returns a GD object, for example:
    my $gd = graph->plot(...); my $format = $my_graph->export_format; print header("image/$format"); binmode STDOUT; print $gd->gif;
Re: Creating a Histogram
by Herkum (Parson) on Apr 19, 2006 at 13:50 UTC
    You should do this, you break your HTML page into one script and your graph into another script. Within your HTML page you call the graph script passing it parameters that it will need to draw the graph.
    <!-- Your HTML page --> <html> <body> <h1>My Graph</h1> <p><img src="graphic.pl?width=100&height=100"> </body> </html>
    Now your script that will return the graph,
    use CGI; my $q = CGI->new(); my $height = $q->param('height'); my $width = $q->param('width'); # # Include you GD stuff here... #

    I realize that this is not complete but neither is the code that you gave us to work with... :)

Re: Creating a Histogram
by GrandFather (Saint) on Apr 19, 2006 at 10:31 UTC

    Too much code, too much data, far too much cruft. Thin the problem down to about 10-20 lines of code that can be run without depending on anything except the image manipulation modules (GD::*).

    My guess is that you are missing a GIF plugin of some sort, but there is no way I'm going to bother setting up an entire system just to find that out for you and given the paucity of replies so far, I doubt many others are driven to reply until the wood has been thined a little so the trees can be seen.


    DWIM is Perl's answer to Gödel