Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Newbie using modules

by diffredential (Beadle)
on Oct 05, 2008 at 19:28 UTC ( #715451=perlquestion: print w/replies, xml ) Need Help??

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

Hi Monks! new user here! I'm new to Perl (I know the basic syntax) and I get really surprised when I saw CPAN. Really amazing community. So I decided to download a first module and try it. I started downloading Email::Send::Gmail and proceed with the installation but it crashed so hard because a lot of other modules needed lol. So I tryed with something easier: Chart::Gnuplot http://search.cpan.org/~kwmak/Chart-Gnuplot-0.05/lib/Chart/Gnuplot.pm#output Everything installed fine, but when I try to run in my computer the little example of the website:
use Chart::Gnuplot; my $chart = Chart::Gnuplot->new( output => "/home/diffredential/Desktop/expression.png" ); my $dataSet = Chart::Gnuplot::DataSet->new( func => "sin(x)" ); $chart->plot2d($dataSet);
I have installed gnuplot (just run sudo apt-get install gnuplot on my Ubuntu). So I guess an image called expression.png should appear in the Desktop after running "perl myscript.pl". But it doesn't. I guess that's not a bug of the module since is a very trivial example. Anyone can help me getting the image? or at least I'm curious to see gnuplot plotting something. Thanks Monks!

Replies are listed 'Best First'.
Re: Newbie using modules
by moritz (Cardinal) on Oct 05, 2008 at 19:42 UTC
    but when I try to run in my computer the little example of the website:

    ... then what exactly happens? That's the most interesting part, and the thing you left out.

    (Please also read What shortcuts can I use for linking to other information?).

    Update: I looked at the strace output, and it seems that the image is written to a temporary file first, and only later copied or moved to its destination path. So you should check if the permissions of your tmp directory are ok, and if you have space left on that device.

      Sorry your right!! Exacty nothing happens:
      diffredential@fredlab:~/Desktop$ perl myscript.pl diffredential@fredlab:~/Desktop$
      !!

        It seems that the synopsis of the module is incomplete. From reading the documentation further down, there is a ->output($filename) method which writes the chart as an image file to disk. So maybe you have to add another line after the ->plot2d:

        ... $chart->output('mychart.png');
        ... and ls doesn't show a expression.png file? (The desktop view might not be updated immediately, so use ls to check).

        I tried your script (with a different path, of course), and it worked, and with a wrong output path (ie non-existing path) an error message is shown.

        If you are sure that the file is not created, you might try to run your script with strace to find out if a system call failed:

        strace -f perl myscript.pl

        (Update: If you don't know how to read the output from strace, post the last 30 to 50 lines here (in <readmore><code>...</code></readmore> tags), maybe somebody can enlighten you).

        Please check the following:
        1. Type gnuplot --version to check whether gnuplot can be executed.
        2. Check whether the directory /tmp is already full.
        3. Check whether you have write permission of /tmp.

        If they are all fine, then you should be able to use at least the basic features of Chart::Gnuplot. Please re-try your original script with expression.ps as output instead (ps format is more basic than png for the module).

        You don't need the method ->output($filename) although there is no harm to do so. The output method is useful only in cases where you don't know the output filename yet when you create the chart object.

        If you got expression.ps, then it may be the problem of ImageMagick. Please check whether it is installed.

        If you don't want to install ImageMagick and if you want to generate png file. You may try:

        my $chart = Chart::Gnuplot->new( output => "/home/diffredential/Desktop/expression.png", terminal => "png" );

Re: Newbie using modules
by b10m (Vicar) on Oct 05, 2008 at 19:50 UTC
    "So I decided to download a first module and try it. I started downloading Email::Send::Gmail and proceed with the installation but it crashed so hard because a lot of other modules needed lol."

    Depending on your Perl version, you will have the CPAN (and CPANPLUS with 5.10) installed. These modules can handle downloading and installing dependencies for you. For more info, please see: CPAN and CPANPLUS

    --
    b10m
      Thanks you all for answering!!! I've added that line $chart->output('/home/diffredential/Desktop/expression.png'); and nothing happened. The strace command gave a lot of complicated output to check anything for me! I downloaded the CPAN module some days ago, but I coudn't figure out how to use it having the Email::Send::Gmail tar gz file. I run in the interactive module "install Emaill...tar.gz" and start doing something but crashed at some point. Wow can't understand why it works to some of you and not for me :(
        Show us some of the "complicated output", the last 30 to 50 lines should be the most interesting (in <c> and code tags please).
        Any idea? kinda weird :S really simple script with a simple module , :S anyone knows how to plot the image with gnuplot instead of saving it into an image? (maybe the problem is there)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://715451]
Approved by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2022-07-06 16:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?