#!/usr/bin/perl use strict; use warnings; use Data::Dumper; use GD::Graph::histogram; sub createGraphs { my ( $HoHoA ) = @_; for my $hashRef ( keys %$HoHoA ) { for my $line ( sort keys %{ $HoHoA->{$hashRef} } ) { my $graph = new GD::Graph::histogram(400,600); $graph->set( x_label => 'X Label', y_label => 'Count', title => "Histogram From: $hashRef line number $line", x_labels_vertical => 1, bar_spacing => 0, shadow_depth => 1, shadowclr => 'dred', transparent => 0, ) or warn $graph->error; my $gd = $graph->plot($HoHoA->{$hashRef}{$line}) or die $graph->error; open(my $IMG, ">", substr($hashRef, 0, -4).'_'.$line.'.png') or die "Unable to save the graph: $!"; binmode $IMG; print $IMG $gd->png; close($IMG) or die "Unable to close image save: $!"; } } return; } my %HoHoA; while (<>) { chomp; push @{ $HoHoA{$ARGV}{$.} }, split(/,/, ) if (index($_, ',') != -1); } continue { close ARGV if eof; } # print Dumper \%HoHoA; # view the complex structure createGraphs( \%HoHoA ); __DATA__ ~/PerlMonks$ cat data.txt 1,5,7,8,9,10,11,3,3,5,5,5,7,2,2 2,6,7,8,9,15,17,3,4,5,6,5,7,2,3 __END__ ~/PerlMonks$ ls -la | grep data -rw-r--r-- 1 user user 2080 Sep 1 01:48 data_1.png -rw-r--r-- 1 user user 2015 Sep 1 01:48 data_2.png -rw-r--r-- 1 user user 64 Sep 1 01:47 data.txt