use strict; use diagnostics; use DBI; my $db = DBI->connect("dbi:SQLite:dbname=rivers.db") or die $DBI::errstr; my $stations_st = $db->prepare("select id, name, watercourse from stations"); $stations_st->execute(); my $stations = $stations_st->fetchall_hashref("id"); my $watercourses = {}; foreach my $station (keys %{$stations}) { push @{$watercourses->{$stations->{$station}->{watercourse}}}, $station; } print <{$watercourse}}) { push @plots, qq( "< sqlite3 -init plot.sqliterc rivers.db 'select timestamp, level from levels where stationid = $stationid'" using 1:2 title "$stations->{$stationid}->{name}" with linespoints); } print join(", \\\n", @plots), "\n"; }