Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

commented out s/// prevents script running!

by Anonymous Monk
on Mar 03, 2004 at 10:14 UTC ( #333502=perlquestion: print w/replies, xml ) Need Help??

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

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"; }

jdporter - added readmore tags

Replies are listed 'Best First'.
Re: commented out s/// prevents script running!
by Corion (Patriarch) on Mar 03, 2004 at 10:50 UTC

    You are using Switch.pm, which has to parse your source code. And obviously, Switch is thrown off by some stuff you commented out. Don't use Switch or other modules that reparse your source code when commenting out other code inside it.

      Thanks for the replies; The block at the end is only commented out becasue I have been trying to isolate my problem. You can uncomment the entire while loop, put the correct end-brace in position and re-instate the original conditional for the while loop, but I still get the same problem, .. so, I dont think having commented code inside my switch is causing it. I have double checked, triple, quadruple checked the {}'s and '' 's and ""'s all is fine. The error I get on running the script WITH the #s/// line is; syntax error at tsm_processjob.cgi line 233, near "}continue" syntax error at tsm_processjob.cgi line 235, near "}"
Re: commented out s/// prevents script running!
by tinita (Parson) on Mar 03, 2004 at 11:22 UTC
    i think this is very much code, and i'm not attempting to run it, as i don't have the right modules, and as it isn't strict safe. isn't it possible to comment out the Pg and GD things and just leave the basics?
    anyway, i commented out the Pg and GD use statements, and i'm getting 'Syntax ok' on perl 5.8.2 with Switch.pm 2.10, and
    syntax error at skript.pl line 260, near "}continue" syntax error at skript.pl line 262, near "}"
    with 5.8.0 and Switch.pm 2.09. so just try to upgrade Switch.pm, this should help.

    Update:: using strict and warnings would of course be helpful, too, as always.

Re: commented out s/// prevents script running!
by matija (Priest) on Mar 03, 2004 at 11:27 UTC
    What version of Perl Are you running? I tried your script here (This is perl, v5.8.3 built for i386-linux-thread-multi), uncommented your loop, and perl -wc reports no problems with your s// statement either active, OR commented out. The only other change I did was to fix this error message:
    Unquoted string "carsington" may clash with future reserved word at /home/matija/downloads/index.pl line 39
    
    by quoting the word carsington.

    I'm getting a few called too early to check prototype errors, and two used only once errors, but no syntax errors.

      Thanks again perlish peeps; I am running perl 5.8.0, I have just tried installing Switch 2.10 and see the same problems. I am about to try the latest version of Perl too. btw; the README for Switch 2.10 did not mention anything RE: uninstalling previous switch versions. So, I installed it over the top of the old switch install. Could this be a problem; IE, Am I still using a pre-2.10 switch as I didnt remove the old switch first?? Thanks, Matt.
        I havent yet tried with perl 5.8.3, so I am still running 5.8.0, but i + did this; perl -d tsm_processjob.cgi and the debugger say's; Switch::filter_blocks(/usr/lib/perl5/5.8.0/Switch.pm:94 94: component: while (pos $source < length $source) 95: { Does this give anyone any hints?? also, regarding perl 5.8.3, I did a succesful make, install, from the +perl source distribution etc.. but I can still only find 5.8.0 on my +system. What gives? Thanks, Matt.
Re: commented out s/// prevents script running!
by Elgon (Curate) on Mar 03, 2004 at 10:48 UTC

    Umm,

    Have you tried turning on warnings and rerunning it - you don't give any diagnostic messages, which would make your life considerably easier. It might well be worth use strict; ing too, given the size of the script.

    My guess is that you've incorrectly escaped/matched a quote somewhere and blown though some lines...

    Elgon

    "Stercus! Dixit Pooh. Eeyore, missilis lux navigii heffalumporum iaculas. Piglet, mecum ad cellae migratae secundae concurras."

    PS - You also may wish to consider using transobliteration instead of substitution as it is quicker.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://333502]
Approved by broquaint
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2023-11-30 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?