frustrated in installing modules

E

Ela

I use a function from GD::Graph::chart

and then it prompts me that no such module exists. Fine, using cpan to
install that, it says no such a module. back one level, install GD::Graph.
Ok, it's installed but still error persists. force install helps little.
Similar errors occur quite often and I'm really frustrated about this. Could
anybody tell me what's going wrong?
 
S

smallpond

I use a function from GD::Graph::chart

and then it prompts me that no such module exists. Fine, using cpan to
install that, it says no such a module. back one level, install GD::Graph.
Ok, it's installed but still error persists. force install helps little.
Similar errors occur quite often and I'm really frustrated about this. Could
anybody tell me what's going wrong?

I suggest you re-read the documentation:

GD::Graph::chart->new([width,height])

"chart is either bars, lines, points, linespoints, area, mixed or
pie."


It would be nice if when you post, you give some code and the actual
error that you are getting instead of your interpretation. Makes
it a lot easier to help you.
 
E

Ela

smallpond said:
It would be nice if when you post, you give some code and the actual
error that you are getting instead of your interpretation. Makes
it a lot easier to help you.

The codes are as follows and now the problem becomes "Can't call method
"png" on an undefined value at plot_ss_b.pl line 34." printing error message
or not does not lead to great difference... The input file is like this:
==========
9 ~ 20.03
10 E 14.56
11 E 12.16
==========

#!/usr/bin/perl

use GD::Graph;
use GD::Graph::bars;

$filename = $ARGV[0];

open(FP, $filename);

while ($line = <FP>) {
@words = split(/ /, $line);
if ($words[1] =~ /[A-Z]/) {
push @x, $words[0];
push @y, $words[2];
}
}

@data = (@x, @y);

close FP;

print $data[0], $data[1];

my $graph = GD::Graph::bars->new(400, 300) or die GD::Graph->error;

$graph->set(
title => 'B vs SS',
) or die $graph->error;

#open(IMG, ">$filename.gif") or die $!;
open(IMG, ">$filename.png") or die $!;
binmode IMG;
#$gd = $graph->plot(\@data)->gif;
$graph->plot(\@data)->png or die $graph->error;
print IMG $gd;
close IMG;
 
J

J. Gleixner

Ela said:
The codes are as follows and now the problem becomes "Can't call method
"png" on an undefined value at plot_ss_b.pl line 34." printing error message
or not does not lead to great difference... The input file is like this:
==========
9 ~ 20.03
10 E 14.56
11 E 12.16
==========

#!/usr/bin/perl

use GD::Graph;
use GD::Graph::bars;
Missing:

use strict;
use warnings;
$filename = $ARGV[0]; my $filename = $ARGV[0];

open(FP, $filename);
And if it fails???..
open( my $fp, '<', $filename ) or die "Can't open $filename: $!";
while ($line = <FP>) {
@words = split(/ /, $line);
if ($words[1] =~ /[A-Z]/) {
push @x, $words[0];
push @y, $words[2];
}
}

@data = (@x, @y);

This is not the correct data structure. Fix this
and it should work... provided you have the PNG
libraries.

close FP; close( $fp );

print $data[0], $data[1];
This should print ARRAY(...) if @data is correct. Easiest to use
Data::Dumper to print the values;

use Data::Dumper;
print Dumper( @data );
my $graph = GD::Graph::bars->new(400, 300) or die GD::Graph->error;

What formats can you use?

print 'Supported formats: ', join( ',', $graph->export_format ), "\n";

die "Need PNG libs" unless $graph->can( 'png' );
$graph->set(
title => 'B vs SS',
) or die $graph->error;

#open(IMG, ">$filename.gif") or die $!;
open(IMG, ">$filename.png") or die $!;
binmode IMG;
#$gd = $graph->plot(\@data)->gif;
$graph->plot(\@data)->png or die $graph->error;
print IMG $gd;

print IMG $graph->plot(\@data)->png;

or

$graph->plot( \@data );
print IMG $graph->png;
close IMG;

Start with the examples in the documentation. If they work,
then you know it's something in your code.
 
A

A. Sinan Unur

Ela said:
$filename = $ARGV[0];
my $filename = $ARGV[0];

I prefer

my ($filename) = @ARGV;

Then, adding another command line parameter results in only having
to change the LHS of the statement:

my ($filename, $device) = @ARGV;

Of course, one can only get so much out of positional parameters but
works for quick and dirty scripts.

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
A

A. Sinan Unur

Problem solved... Very, very sorry for causing inconvenience...
sorry

No need to be so sorry to have asked for help. However, next time, you
can improve your chances of being able to help yourself by reading and
following the suggestions in the clpm guidelines. They are posted here
regularly (also, see my sig).

Sinan

--
A. Sinan Unur <[email protected]>
(remove .invalid and reverse each component for email address)

comp.lang.perl.misc guidelines on the WWW:
http://www.rehabitation.com/clpmisc/
 
E

Ela

Thanks smallpond, J. Gleixner and A. Sinan Unur.

With your support I am near to finish. Now the only puzzling thing is that
contradictory results occur:

Supported formats: gif,png,gd,gd2
Need PNG libs at plot_ss_b.pl line 42.

with the following code excerpt, how come it says it support png but at the
same time dies? If I comment the die line, ok, it plots normally but without
anything generated. Finally, why I give this post "frustrated" is that Perl
FAQ, google, or codes message itself give few hints on getting relevant
dependencies. If I have to install whatever PNG, GIF libraries and so, I
don't mind. But the problem is that I don't know whether it is that problem,
and where to locate the libraries directly and correctly.

#@data = ([@x], [@y]);
@data = ([2,3,4], [1,1,1]);
#@data = (@x, @y);
close FP;

print 'Supported formats: ', join( ',', $graph->export_format ), "\n";
die "Need PNG libs" unless $graph->can( 'png' );

$graph->plot(\@data)->png or die $graph->error;
close IMG;
 
J

J. Gleixner

Ela said:
Thanks smallpond, J. Gleixner and A. Sinan Unur.

With your support I am near to finish. Now the only puzzling thing is that
contradictory results occur:

Supported formats: gif,png,gd,gd2
Need PNG libs at plot_ss_b.pl line 42.

with the following code excerpt, how come it says it support png but at the
same time dies? If I comment the die line, ok, it plots normally but without
anything generated. Finally, why I give this post "frustrated" is that Perl
FAQ, google, or codes message itself give few hints on getting relevant
dependencies. If I have to install whatever PNG, GIF libraries and so, I
don't mind. But the problem is that I don't know whether it is that problem,
and where to locate the libraries directly and correctly.

#@data = ([@x], [@y]);
@data = ([2,3,4], [1,1,1]);
#@data = (@x, @y);
close FP;

print 'Supported formats: ', join( ',', $graph->export_format ), "\n";
die "Need PNG libs" unless $graph->can( 'png' );

That was just there as a different way to test for an
available format.

Hmm.. maybe I got that wrong.. After consulting the
documentation, which you can do via

perldoc GD::Graph

that should probably be:

die "Need PNG libs" unless $graph->gd->can( 'png' );

or

my $gd = $graph->plot(\@data) or die $graph->error;
die "Need PNG libs" unless $gd->can( 'png' );

$graph->plot(\@data)->png or die $graph->error;

You need to write that output to your file.
close IMG;

There are many examples in the distribution, take
a look at those too. From the perldoc:

"EXAMPLES
See the samples directory in the distribution, and read
the Makefile there. "
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,684
Latest member
sparada

Latest Threads

Top