in reply to Graphing basics..
Here's a little snippet that I came up with that will put the correct data in @data. It was an interesting little problem and I wanted to play with it. You may have to tweak it to get it to do exactly what you want, but it should give you a headstart. There are a few things in there which may be confusing, so feel free to ask questions.
use strict; # returns the data as an array ref my $data = get_graph_data('header_data.dat', 'daily_data*.dat'); sub get_graph_data { my ($header,$file_name_format) = @_; my @dailies = glob($file_name_format); my @data; @dailies = map { $_->[0] } sort { $a->[1] <=> $b->[1] } map { [ $_, get_number_in_string($_) ] } @dailies; foreach my $file ( $header, @dailies ) { local *IN; open IN, "< $file" or die "Cannot open ($file) for reading: $ +!"; push @data => [<IN>]; close IN or die "Cannot close ($file): $!"; } return \@data; } sub get_number_in_string { # returns the first instance of one or more digits in string my $string = shift || ''; my ($number) = $string =~ /^([[:digit:]]+)$/; return $number; }
Cheers,
Ovid
New address of my CGI Course.
Silence is Evil (feel free to copy and distribute widely - note copyright text)
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Graphing basics..
by Anonymous Monk on Feb 28, 2003 at 03:26 UTC |