Hi, I got this scrip that is suppsed to use the use the Getopt::Std; and GD::Graph::bars; to input generate an array from a file (age). With this array, the GD::Graph::bars is going to create a subroutine printHistogram() which generates a png file based on a supplied array. The signature of the method could be like this: printHistogram(\...@histy,"$filename",$histmin,$histmax,"Title");
I manage to generate the array from the input file, but it seems like there is something wrong with my subroutine at the end, I have been using the examples at cpan.org as an templat for this subroutine. Following is the error msg, as well as the complete script. Tnx! The ERROR msg: hostname$ ./bars.pl -f age ./bars.pl: line 5: use: command not found Array found where operator expected at ./bars.pl line 90, at end of line (Might be a runaway multi-line // string starting on line 53) (Missing operator before ?) Global symbol "$title" requires explicit package name at ./bars.pl line 53. Global symbol "$graph" requires explicit package name at ./bars.pl line 53. Global symbol "$graph" requires explicit package name at ./bars.pl line 53. Global symbol "$title" requires explicit package name at ./bars.pl line 53. Global symbol "$graph" requires explicit package name at ./bars.pl line 53. Global symbol "$gd" requires explicit package name at ./bars.pl line 53. Global symbol "$graph" requires explicit package name at ./bars.pl line 53. syntax error at ./bars.pl line 90, near "my $gd = $graph->plot(/@array" Global symbol "$graph" requires explicit package name at ./bars.pl line 90. Global symbol "$gd" requires explicit package name at ./bars.pl line 95. Unmatched right curly bracket at ./bars.pl line 97, at end of line ./bars.pl has too many errors.' #!/usr/bin/perl -w # Needed pkg use Getopt::Std; use strict; use warnings; use GD::Graph::bars; # Global variables my $VERBOSE = 0; my $DEBUG = 0; ################################################################ # handle flags and # Example: c == "-c", c: == "-c argument" my $opt_string = 'hvdf:'; getopts( "$opt_string", \my %opt ) or usage() and exit 1; # exit other than 0 = error!! # print help message if -h is invoked if ( $opt{'h'} ){ usage(); exit 0; } $VERBOSE = 1 if $opt{'v'}; $DEBUG = 1 if $opt{'d'}; my $FILENAME = $opt{'f'}; # main program content my $filename = $FILENAME; my $line; my @dataarray; my @array; my $counter; my $histmin; my $histmax; open (FILE, "$filename") or die ("ERROR: $!\n"); while ($line = <FILE>){ debug($line); chomp $line; @array = split / /, $line; @array = sort @array; $histmin = $array[0]; $histmax = $array[-1]; $counter++; } # print "$histmin\n$histmax\n"; # print "min: $array[0]\nmax: $array[-1]\n"; # print "@dataarray\n"; printHistogram(/@array,$filename,$histmin,$histmax,'Age'); ########################################## # Helper routines sub usage { # print the correct use of this script print "Usage:\n"; print "-h Usage\n"; print "-v Verbose\n"; print "-d Debug\n"; print "-f Filename\n"; } sub verbose { print $_[0] if ( $VERBOSE or $DEBUG ); } sub debug { print $_[0] if ( $DEBUG ); } sub printHistogram { my (@array,$filename,$histmin,$histmax,$title) = @_; my $graph = GD::Graph::bars->new(400, 300); $graph->set( x_label => 'X Label', y_label => 'Y label', title => '$title', y_max_value => $histmax, y_min_value => $histmin, y_tick_number => 8, y_label_skip => 2 ) or die $graph->error; my $gd = $graph->plot(/@array) or die $graph->error; open(IMG, '>$filename.png') or die $!; binmode IMG; print IMG $gd->png; close IMG; -- To unsubscribe, e-mail: beginners-unsubscr...@perl.org For additional commands, e-mail: beginners-h...@perl.org http://learn.perl.org/