in reply to Re: Problem with creating Files (maybe)
in thread Problem with creating Files

I was thinking of such solution, but I simply do not know where to put that path of code. Because the HTML is generated only after it returns to .PL.

in .PL i use createBarchart and doesn't have any output, since he creates the file with:

open ($outfile, ">", $dir.$filename)||die "Couldnt open the file!\n" +; (@outputHead) = createHeader($outfile,$filename); print $outfile " @outputHead\n"; print $outfile " [@legendArrayBAR],\n"; for($j=0; $j<$rows;$j++){ print $outfile "['$valueMatrixBAR[$j][0]'," +; for($i=0; $i<$cols-1;$i++){ print $outfile " $valueMatrixBAR[$j +][$i+1],"; if($loop_cou +nt == $cols-2){ $line +=~ s/,+$//; } $loop_count++; } print $outfile "],\n"; } print $outfile " ]); var options = { 'width': 800, 'height': 400, title: '$title', hAxis: {title: 'Sprint', titleTextStyle: {color +: 'red'}} };\n var chart = new google.visualization.ColumnChart( +document.getElementById('chart_div')); chart.draw(data, options); }\n"; (@outputFoot) =createFooter($outfile,\@CustomerList,\@SprintList,$fi +lename); print $outfile "@outputFoot\n"; #print "Finished writting a file\n"; close ($outfile);

I hope this code won't confuse you. It has to be like that, so it can be used generally, not just for this case. But there might be sometimes a new Database, and everything I need to add then is the unique ID of that database, and everything should work like that.

Replies are listed 'Best First'.
Re^3: Problem with creating Files (maybe)
by Anonymous Monk on Jul 25, 2014 at 10:10 UTC

    I was thinking of such solution, but I simply do not know where to put that path of code.

    put it in createButtons, the part that prints links, we're talking about createButtons, right?

    if none of the files exist yet , causing createButtons to be mostly fakeLink, just run the program twice  DoIt(); DoIt(); on first run, lots of the links will be wrong, but on the second run, the links will be right

    I hope this code won't confuse you.

    The code isn't confusing :) but seems to be missing JSON

      I cannot use JSON as we do not have web server. Everything has to be done locally. JSON-P unfourtanetly didnt work also, so I went for the HASH filling option.

      if nothing else, I got too confused in everything. How sould the part if exist look like?

      I understand why it needs a second run as in the first run, the first HTML's will always say that file does not exist, but later on, it will.

      Sorry for my stupidness, but if you tell me what should I write, it'll save me.

       if(-e $filename){ print ....} else { ..?}

      That's how I would do it. Can you please corect me?

        Sorry for my stupidness, but if you tell me what should I write, it'll save me.

        Write more subs , debug small subs, write more subs ... easier to trace ... like this

        Once you get more of these you're realize you probably want to have createButtons return a string or array of strings so fillFile instead of using  createButtons( $outfile, $filename ); would use  print $outfile createButtons( $filename );