Sponsored Content
Full Discussion: Perl script error
Top Forums Shell Programming and Scripting Perl script error Post 302246718 by pietie on Tuesday 14th of October 2008 07:48:34 AM
Old 10-14-2008
Perl script error

Hi all

I keep getting a segmentation fault error while running the script below.

Code:
#!/usr/bin/perl -w
use CGI ':standard';
use GD::Graph::pie;
use strict;
use warnings;

sub trim($)
{
        my $string = shift;
        $string =~ s/^\s+//;
        $string =~ s/\s+$//;
        return $string;
}


my ($ts, $filename, @array, $line, $arri , $k , $total);

open(DOMAINS, "< /mailstats/temp/domains.tmp") || die "Couldn't open. Please check permissions. \n";

$k = 0;
$total = 0;

while ($line = <DOMAINS>) {
$line = trim($line);
#chomp $line; # removes the carriage return
#@array = split(/ / , $line); # breaks the line up into fields

($array[1][$k], $array[0][$k], undef) = split(" ", $line);

$total = $total + $array[1][$k];

#print $array[0][$k] , "\
print $total , "\n";

my $mygraph = GD::Graph::pie->new(300, 300);
$mygraph->set(
    title       => 'Grading Policy for COP5555 course',
    '3d'          => 0,
) or warn $mygraph->error;

$mygraph->set_value_font(GD::gdMediumBoldFont);
my $myimage = $mygraph->plot(\@array) or die $mygraph->error;

#print "Content-type: image/png\n\n";
open(PICTURE, ">filesplittest.png") or die("Cannot open file for writing");
binmode PICTURE;
print PICTURE $myimage->png;
close PICTURE;
t" , $array[1][$k] , "\n";

## NOW PROCESS EACH LINE HERE


$k = $k + 1;
}
close DOMAINS;

now when I comment out the whole graph drawing block, I don't get a segmentation fault.

The data I am using is a lot of data. Can that be the issue?

If the data is the problem, is there any way I can optimize it?

I have tried inputting less data intro the text file, and it worked.

Regards

Last edited by otheus; 10-14-2008 at 12:54 PM.. Reason: I think down-thumb is not going to help ge this answered.
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Perl Error with ftptail script

Hello everyone, I'm a starting website admin who 2 days ago decided to make the move from shared hosting to a vps on a linux (ubuntu 8.04) platform. This opened a whole new world for me, since I never worked with the console, SSH, linux,... before. I managed to get LAMP setup after a day of... (2 Replies)
Discussion started by: Cooki3s!
2 Replies

2. Shell Programming and Scripting

error in output of perl script

Hi, This is my piece of code. my $logFile = $ARGV; die "usage: $0 <logFile>" unless $logFile; die "Logfile $logFile doesn't exist" unless -f "$logFile"; open(my $log, "<", $logFile) or die "Can't open $logFile for reading."; print "Processing file $logFile...\n"; #my $authenticates... (2 Replies)
Discussion started by: namishtiwari
2 Replies

3. Shell Programming and Scripting

Need help understanding perl script error

I solicited this site earlier this week and got a good answer for a perl Script so I made this script from what understood from the answers But now I have a bug and I'm stump. It doesn't parse correctly the Output it stays on the first line My $f2 and reprints in a endless loop I'm sure there... (3 Replies)
Discussion started by: Ex-Capsa
3 Replies

4. Shell Programming and Scripting

Perl script to rename file,error

#!/usr/bin/perl $FL="ch.txt"; $CFL="mytext.txt"; print "This script will rename textfiles."; mv $FL $CFL; print "Done."; perl file.pl Error: Can't locate object method "mv" via package "ch.txt" (perhaps you forgot to load "ch.txt"?) at file.pl line 7. (5 Replies)
Discussion started by: cola
5 Replies

5. Shell Programming and Scripting

perl script processing error

open(IN,"input_file") or die "Can't open Input file.\n"; while (<IN>) { chomp; $line = $_; if($line != '') { print "\nprocessing $line\n"; $size = 0; $hrid = $line; @project_id_array = null; $size = @project_id_array;... (3 Replies)
Discussion started by: vishwakar
3 Replies

6. Shell Programming and Scripting

Perl : Error in calling script

I am getting a strange error with perl's inbuilt script flush.pl. I am callling this script in my other script but it kept throwing error: flush.pl did not return a true value at ./abc.pl line 1 abc.pl has: require 'flush.pl'; Not sure why this error is coming. Can someone pls throw... (4 Replies)
Discussion started by: abhisharma23
4 Replies

7. Shell Programming and Scripting

Error in executing Perl script

Hello All I am facing an issue The unix script is running fine in unix environment which uses ssh connection but when I try to run the same in informatica environment (same server where I was running the unix script manually successfully) its showing the below error command-line line 0:... (11 Replies)
Discussion started by: Pratik4891
11 Replies

8. Programming

getting error in my perl script

hi Here is my code written to identify the particular position which is after a string (chr*). my input file looks some thing like this aaanbb:anhn:iuopl:12345 chr1 12345 asnmkol * # kjiiii.....anmkij:lpolk:lopll:abnnj chr5 123222 polko * dddfgg .... aaanbb:anhn:iuopl:aanjuj chr2 44345 asnmkol... (1 Reply)
Discussion started by: anurupa777
1 Replies

9. Homework & Coursework Questions

A2p, error in the perl script?

1. The problem statement, all variables and given/known data: filename = awkdata Part 1: Write an awk program that removes the first field and prints only those lines where the third field is greater than 15 million. Part 2: Do the same command above, but with perl instead of awk.... (0 Replies)
Discussion started by: AZbase10
0 Replies

10. Shell Programming and Scripting

Slight error with my perl script that I could use some help on

So I have a perl script that prompts the user to enter either q or Q to exit the program or c to continue said program. If the user inputs anything other than those three keys they will be prompted again and again for an appropriate input. My script works for the most part except for one small... (6 Replies)
Discussion started by: Eric1
6 Replies
Graph::FAQ(3pm) 					User Contributed Perl Documentation					   Graph::FAQ(3pm)

NAME
GD::Graph::FAQ - Frequently asked questions DESCRIPTION
I get errors like "Can't call method METHOD on an undefined value". What gives? You probably had an error somewhere, most likely in the plot() method, and you didn't check for it. See the section on Error Handling in the documentation for GD::Graph to find out how to deal with this sort of thing, and how to get more information about what the error was. I am drawing a bar chart, and the chart area is a lot smaller than the image. What is going on? As of version 1.30, GD::Graph automatically corrects the width of the plotting area of a chart if it needs to draw bars (i.e. for bars and some mixed charts). This is necessary, because rounding errors cause irregular gaps between or overlaps of bars if the bar is not an exact integer number of pixels wide. If you want the old behaviour back, set the correct_width attribute to a false value. I have my data in some format that doesn't look at all like the array that I am supposed to give to GD::Graph's plot method. Do I really need to mess around with array references? Not necessarily. Check out the GD::Graph::Data class. How do I stop those pesky accents appearing around bars or inside area charts? You can set the "accent_treshold" option to a large enough value (larger than your chart). Alternatively, you may like it better to set the "borderclrs" attribute to be the same as the dclrs one. I'll probably include an option in a future version that gives better control over this. Where is the ActiveState ppm of GD::Graph? Ask them. I have asked them, but didn't get an answer. I don't know what to do to get it included in their set of ppms, and I really do not have the time to keep asking them. I believe that GD::graph has finally made it into ActiveState's ppm archive. However, I am going to leave this question here in case they get behind again. Do you have some example code for me? The distribution has a large set of examples in it. If you don't have the original distribution, please get it from CPAN (http://www.cpan.org/ or some local mirror). Will you support X or Y? If you send me a patch that (in a decent manner) adds the functionality to the latest version, I may very well add it for the next release. If you don't send me a patch, but just a question, you will have to be patient. (Please also see the section on bugs in the main body of GD::Graph.) Why does export_format give me a weird string, instead of just 'png' or 'gif'? As of version 1.31, export_format in a list context returns all formats that GD can export. If you are only interested in the answer 'gif' or 'png', make sure that you call it in a scalar context. $export_format = GD::Graph->export_format; $export_format = $graph->export_format; print "Export format is ", scalar $graph->export_format, " "; print "Export format is " . $graph->export_format . " "; @export_formats = $graph->export_format; TrueType fonts don't work when I use GD::Graph from a CGI program. When your programs run as CGI, they typically do not have the same environment as when you use them from the command line. The Perl FAQ, section 9, has some information on this. It is also not guaranteed that your script runs from the directory that it is in. It is probably better to include something like: use GD::Text; GD::Text->font_path("/path/to/my/font_dir"); See the GD::Text documentation for more information about font paths. I'm trying to use GD's builtin fonts, but it's not working. Most likely, you are using the font short name, like gdGiantFont or gdMediumBoldFont, and you have not put a "use GD" in your program. This is needed, because these short names need to be exported into your name space by the GD library: use GD; # ... $graph->set_x_axis_font(gdMediumBoldFont); If you don't want to include the GD library, you can use the longer alternative names (which is what I'd recommend anyway): $graph1->set_x_axis_font(GD::Font->MediumBold); If you "use strict" then you will actually get an error message if you try to use the short names without including the GD module. Also see the GD::Text documentation for this information. When I have many data sets, some end up having the same colour. The default number of colours for data sets is seven, so if you use more than seven data sets, those colours will be re-used for the higher data sets. This is described in the entry for the "dclrs" attribute in the GD::Graph documentation. Can you tell me how to do X? Not necessarily (X might be kind of complicated, after all). Did you look in the samples for something similar? If not, you're probably best off seeing if you can get help from a group of people, rather than one or the other of the overworked individuals whose e-mail addresses are shown below. If you're more comfortable with asking a newsgroup for help, the canonical resource is <comp.lang.perl.misc>; if you prefer web forums, there is a good one at <http://www.perlmonks.org>. In either case, if you are not familiar with the forum and its denizens, you might wish to read the following helpful guide before posting your question: http://www.perlmonks.org/?node_id=172086 Can you fix this bug I've found? Well, I hope so. Please see the "BUGS" section in the main body of GD::Graph for the best way to report it. AUTHOR
Martien Verbruggen <mgjv@tradingpost.com.au> Current maintenance (including this release) by Benjamin Warfield <bwarfield@cpan.org> (c) Martien Verbruggen. All rights reserved. This package is free software; you can redistribute it and/or modify it under the same terms as Perl itself. perl v5.12.3 2007-04-26 Graph::FAQ(3pm)
All times are GMT -4. The time now is 02:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy