I have the following piece of perl. Notice the large commented-out section toward the end.
My problem is, Why wont this script run unless I deleted a commented-out s/// statement????
More info in the code; NB: I wouldnt normally post all the code, but in this instance I have a feeling the error could be buried anywhere within it....
#!/usr/bin/perl
use CGI ':standard';
use CGI ':cgi-lib';
use Pg;
use GD::Graph::bars3d;
use GD::Graph::bars;
use GD::Graph::lines;
use GD::Graph::lines3d;
use GD::Graph::colour qw(:colours :lists :files :convert);
use Switch;
use Date::Simple (':all');
######################################################################
+#########
#
# Function: Handle web-based TSM jobs
# Version: v1.0 *** nb: This is single script DEV version,
# This is to be split into functional parts.
# Date: 25 Feb 2004
#
# Author: Matt
######################################################################
+#########
# Revision History:
######################################################################
+#########
# DATE REASON
# --------------------------------------------------------------------
+---------
######################################################################
+#########
# Get our headers out first;
print "Content-type: text/html\n\n";
print "<HTML><HEAD> <META http-equiv=\"cache-control\" content=\"no-ca
+che\"> <TITLE>rmm-unixsupport TSM Capacity / Performance</TITLE></HEA
+D><BODY>";
# Set some important Vars
$dbconn=Pg::connectdb("dbname=unixsupport");
$NOCACHE=1;
%formparms=Vars;
$server=carsington;
$object=$formparms{'listServerObject'};
$type=$formparms{'radiogroup1'};
$typedata=$formparms{'textboxDates'};
dbg("server,object,type,data : $server $object $type $typedata");
doanalysisjob("begin",$server,$object,$type,$typedata);
print "</BODY></HTML>";
#begin to step into app, start session, init hidden input fields
#continue to use hidden input fields to continue a session
sub doanalysisjob()
{
($job,$hostname,$object,$type,$typedata)=@_;
##Ok, build graph data
switch ($object)
{
case "LOG"
{
dbg("Setting up objectselect for LOG");
#Querying LOG monitoring info
#
# TO-DO:-
# Instead of hardcoding how to split the 'blobs' apart
+for each server object
# use some DB tables that are updated by the monitor sc
+ripts themselves
# that tell us about a monitored object, how to referen
+ce it & how to atomicise the 'blob'
$objectselect="datafile like '%logwatch'";
}
case "DB"
{
$objectselect="datafile like '%dbwatch'";
}
case "MOUNTS"
{
$objectselect="datafile like '%mountcount'";
}
case "SESSIONS"
{
#
# TO-DO
#
}
case "PROCESSES"
{
#
# TO-DO
#
}
case "STORAGE POOLS"
{
#
# TO-DO
#
}
}
##What kinda daterange are we doing?
##Ok, retrieve the data according to the analysis type
switch ($type)
{
case "SingleDate"
{
#dbg("Doing a single date job");
#
# simple, single
#
#Get data;
$sdate=$typedata;
$query="select dataline from tsm_data where hostname='$hos
+tname' and $objectselect and date=$sdate";
#dbg("Query is $query");
Pg::doQuery($dbconn,$query,\@resultset);
#Split the 'blob' depending on object type
for $record ( 0 .. $#resultset )
{
for $field ( 0 .. $#{$resultset[$record]})
{
switch ($object)
{
case "LOG"
{
($timeval,$pointval)=split (/,/,$resultset
+[$record][$field]);
#dbg("split $timeval , $pointval from LOG blob");
push (@times,$timeval);
push (@points,$pointval);
}
case "DB"
{
($timeval,$pointval)=split (/,/,$resultset
+[$record][$field]);
push (@times,$timeval);
push (@points,$pointval);
}
case "MOUNTS"
{
($timeval,$pointval)=split (/,/,$resultset
+[$record][$field]);
push (@times,$timeval);
push (@points,$pointval);
}
case "SESSIONS"
{
#TO-DO
}
case "PROCESSES"
{
#TO-DO
}
case "STORAGE POOLS"
{
#TO DO
}
}
}
}
@graphdata=([@times],[@points]);
$numpoints=$#points;
#dbg("Going to draw graph");
drawgraph("Time","Utilisation","$object dataset from $date
+",12,1,$numpoints/12,\@graphdata,"${hostname}${object}${type}${date}"
+,"lines3d");
}
case "RangeDate"
{
dbg("Doing Rangedate");
#
# continuous block of dates
# use date functions to count forward days
# Essentially, the same as 'SingleDate', with multiple day
+s data concatenated into the array
# Sort out the date parameters
($sdate,$edate)=split(/ /,$typedata);
$d8sdate=d8($sdate);
$d8edate=d8($edate);
$d8cdate=$d8sdate;
dbg("Got sdate, edate as $sdate,$edate");
####
#
# PERLMONKS! Ok, this is where my problem start. You can see ive 'ner
+fed' the following while-loop just for testing purposes, and to narro
+w down which line I have the problem on.
#
$a=1;
$b=1;
while($a==$b) #($d8cdate<=$d8edate)
{
#dbg("Doing the while thang d8cdate=$d8cdate, d8edate=$d8edate");
# $cdate=$d8cdate;
####
#PERLMONKS! The following $cdate=~s/-//g; is the problem!
#WHY Wont This Script Run Unless I DELETE! that line!!
#
# $cdate =~ s/-//g;
# $query="select dataline from tsm_data where hostname=
+'$hostname' and $objectselect and date=$cdate";
###
#
#PERLMONKES! the following close-curly-brace ends the 'Nerfed' While L
+oop. The 'correct' closing brace is indicated below
#
#
}
# Pg::doQuery($dbconn,$query,\@resultset);
#
# #Split the 'blob' depending on object type
# for $record ( 0 .. $#resultset )
# {
# for $field ( 0 .. $#{$resultset[$record]})
# {
# switch ($object)
# {
# case "LOG"
# {
# ($timeval,$pointval)=split (/,/,$resu
+ltset[$record][$field]);
# push (@times,$timeval);
# push (@points,$pointval);
# }
# case "DB"
# {
# ($timeval,$pointval)=split (/,/,$resu
+ltset[$record][$field]);
# push (@times,$timeval);
# push (@points,$pointval);
# }
# case "MOUNTS"
# {
# ($timeval,$pointval)=split (/,/,$resu
+ltset[$record][$field]);
# push (@times,$timeval);
# push (@points,$pointval);
# }
# case "SESSIONS"
# {
# #TO-DO
# }
# case "PROCESSES"
# {
# #TO-DO
# }
# case "STORAGE POOLS"
# {
# #TO DO
# }
# }
# }
# }
# $d8cdate=$d8cdate+1;
#####
#PERLMONKS! The Following clsoe brace would normally terminate the 'm
+angled' while loop above.
#
#
# }
# @graphdata=([@times],[@points]);
# $numpoints=$#points;
# drawgraph("Time","Utilisation","$object dataset for range $sd
+ate to $edate",12,1,$numpoints/12,\@graphdata,"${hostname}${object}${
+type}${date}","lines3d");
}
}
}
sub drawgraph()
{
($xlabel,$ylabel,$title,$yticknum,$ytickskip,$xtickskip,$datavalues_RE
+F,$outfile,$type)=@_;
@datavalues=@$datavalues_REF;
switch ($type)
{
case "lines3d"
{
#dbg("lines3d graph");
$graph=GD::Graph::lines3d->new(640,400);
$graph->set(
borderclrs =>[qw(orange)],
dclrs =>[qw(orange)],
boxclr =>'lyellow'
)or die $graph->error;
}
case "bars3d"
{
#dbg("bars3d graph");
$graph=GD::Graph::bars3d->new(640,400);
$graph->set(
borderclrs =>[qw(orange)],
bar_depth =>20,#(640/$#{$datavalues[1]})*2,
dclrs =>[qw(orange)],
boxclr =>'lyellow'
)or die $graph->error;
}
case "bars"
{
#dbg("bars graph");
$graph=GD::Graph::bars->new(640,400);
}
}
#dbg("setting up graph");
$graph->set(
long_ticks =>1,
x_label =>$xlabel,
y_label =>$ylabel,
title =>$title,
y_tick_number =>$yticknum,
y_label_skip =>$ytickskip,
x_label_skip =>$xtickskip,
t_margin =>12,
b_margin =>12,
l_margin =>12,
r_margin =>12,
shadow_depth =>2,
box_axis =>0,
) or die $graph->error;
#dbg("set. Plotting graph");
$plotted=$graph->plot(\@datavalues) or die $graph->error;
#dbg("Plotted. Saving image");
open(IMG, ">/data/web/unixsupport/tsm_CNP_imagecache/${outfile}.pn
+g") or die $!;
binmode IMG;
print IMG $plotted->png;
#dbg("Saved , printing link");
print "<img src=\"http://unix/tsm_CNP_imagecache/${outfile}.png\">
+";
}
sub dbg()
{
($msg)=@_;
print "\n<br>\nDBG:${msg}\n<br>\n";
}