[問題]書上了例子不能執行

看板Perl作者 (凍結一切)時間19年前 (2006/08/20 18:44), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
下面的例子是從Mastering Perl for Bioinformatics這本書來的 不知是否有人讀過,裡面有一個例子,當我測試時卻出問題,可是 自己也找不出它錯哪?或許自己太遜了吧!! 我是使用WIN XP系統 ,用ActivePerl 5.8版 以下是書的例子: #!/usr/bin/perl use strict; use warnings; use Carp; use GD::Graph::bars; my %dataset=(1=>3,2=>17,3=>34,4=>23,5=>25,6=>20,7=>12,8=>3,9=>1); my $graph=new GD::Graph::bars(600,300); my ($xmax)=sort{$b<=>$a} keys (%dataset); my ($ymax)=sort{$b<=>$a} values (%dataset); my $yticks=int($ymax/5)+1; my(@xsizes)=(0..$xmax); my(@ycounts)=(); foreach my $x (@xsizes) {if(defined $dataset{$x}){push @ycounts,$dataset{$x};} else{push @ycounts,0;}} $graph->set(transparent=>0,title=>"summary of mutation data", x_label=>'Mutants per cluster',y_label=>'Number of mutant', x_all_ticks=>1,y_all_ticks=>0,y_all_numbers=>$yticks,zero_axis=>0, zero_axis_only=>0,); my $gd=$graph->plot([^xsizes],[^ycounts]); my $pngfile= "gdgraph1.png"; unless(open(PNG,">$pngfile")){croak "Cannot open $pngfile:$!\n";} binmode (PNG); print PNG $gd->png; 在MS-DOS執行下所顯示: Can't call method "png" on an undefined value at 3.pl line 21. 但是在我的perl資料夾中確實有了一個新的圖檔,只是裡面沒有寫入任何的data 不知是哪裡出了甚麼問題?? 請求高手賜教,感恩<(_ _)> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 210.209.155.177
文章代碼(AID): #14w3q0_a (Perl)
文章代碼(AID): #14w3q0_a (Perl)