Younes27 Younes27 - 3 months ago 20
Perl Question

perl How do I create a pie chart with this data?

I have a small program that retrieves data from a CSV file (country name and percentage). I stored the country's name in a file

and the percentage of each country in

I want to represent the data in graph.

Here's what I have written

use strict;
use warnings;

use Text::CSV;
use GD::Graph::bars;
use GD::Graph::Data;

my $filename = "out.csv";
my $input1 = 'f1.txt';
my $input2 = 'f2.txt';

open( OUT1, '>' . $input1 ) or die( "can't open $input1. \n" );
open( OUT2, '>' . $input2 ) or die( "can't open $input2. \n" );

sub main {

print "Entrez la valeur : ";
my $val;
chomp( $val = <STDIN> );

open( INPUT, $filename ) or die "Cannot open $filename";
my $line = <INPUT>;

print "les pays ou les accident sont a cause de la TraFic sont :";

while ( $line = <INPUT> ) {

chomp( $line );
my ( $name, $name2, $purcent, $purcent1, $purcent2, $purcent3, $purcent4, $purcent5 )
= split( ' ', $line );

if ( $name2 > $val ) {
print "$name\t$name2\t\n";
print OUT1 "$name\n";
print OUT2 "$name2\n";
print "\n";


I found examples where the data was entered manually, but this time I want to recover it from a text file (the data changes dynamically)


this is good, so stacking the recovered data in a table with the push function and after it is passed by reference .graph (\ @ Country, \ @Purcent);