Click here to get back home

frustrated in installing modules

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
frustrated in installing modules Ela 04-03-2008
Posted by Ela on April 3, 2008, 11:04 am
Please log in for more thread options
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?



Posted by smallpond on April 3, 2008, 11:27 am
Please log in for more thread options
> 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.

Posted by Ela on April 3, 2008, 11:39 am
Please log in for more thread options

> 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;






Posted by J. Gleixner on April 3, 2008, 1:22 pm
Please log in for more thread options
Ela wrote:

> 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>) {
while ( my $line = <FP> ) {
chomp( $line ); # or could chomp $words[2] in if()

> @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.

Posted by A. Sinan Unur on April 3, 2008, 2:23 pm
Please log in for more thread options

> Ela wrote:
>
>> $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

--
(remove .invalid and reverse each component for email address)

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

Similar ThreadsPosted
installing modules? September 29, 2005, 9:18 pm
installing modules June 5, 2006, 9:13 am
Installing Perl modules May 24, 2006, 5:13 am
OS X, installing modules from CPAN November 13, 2007, 10:58 am
installing perl modules and ports September 16, 2004, 12:36 pm
installing architecture dependent modules March 2, 2005, 8:17 pm
Installing modules locally as a non root May 23, 2005, 5:21 am
installing perl and some modules on many hosts December 28, 2005, 10:34 pm
Errors using installing perl modules November 29, 2007, 1:26 pm
installing perl modules on windows July 15, 2008, 12:22 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap