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

Hello Monks!

I have a perl script, when I run it, I output it to a text file or a php page. When I view it from either the file or the php page, the return data is all part of 1 line, and I need it to list. I've tried new line and other forms just can't seem to get it. Any help would greatly be appreciated. Here is the out put. Jobs with start and end time. the "*" just means the job hasn't ran yet.
Job_A, 16:06:38 10/15/2008, 14:55:21 02/23/2009 Job_B, 17:39:16 03/23/ +2009, 17:47:44 03/23/2009 Job_C, ******** **********, ******** ****** +**** Job_D, ******** **********, ******** ********** Job_E, ******** +**********, ******** ********** Job_F, ******** **********, ******** +**********
I need it to look like this
Job_A Start Time End Time Job_B Start Time End Time Job_C Start Time End Time etc....
Here is the code
&DBEXEC("select job_name, last_start, last_end from job_status, job where job.joid = job_status.joid and job_name in ('Job_A', 'Job_B', 'Job_C', 'Job_D', 'Job_E', 'Job_F')"); while(@status = &dbnextrow($dbproc)){ $name = ($status[0]); $stime = &GETTIME($status[1]); $etime = &GETTIME($status[2]); print "$name, $stime, $etime\n";
What do I need to add or remove ?

Replies are listed 'Best First'.
Re: Printing issue with an array
by CountZero (Bishop) on Apr 10, 2009 at 06:23 UTC
    At the very least you are missing a closing curly brace at the end of the while loop.

    Most probably you do not need the &-sigils in the subroutine calls (if you do not understand why you do not need them, then it is almost certain you do not need them, otherwise have a look at perldoc perlsub).

    Other than that, your program seems to work, BUT:

    • You are not printing to a file, so how could you check that all output was on one line? Did you redirect STDOUT perhaps in the shell?
    • How can you see the output from your perl-script in the PHP page? What is the mechanism to transfer the perl-script's output to PHP?
    My guess is that you have to look at the interface between the perl-script and your file and/or PHP page and that somewhere there the EOL-characters get messed up.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Re: Printing issue with an array
by vinoth.ree (Monsignor) on Apr 10, 2009 at 03:52 UTC

    Use Data::Dumper and print the value of @status array, to check whether how the value you are getting in this array.

    Vinoth,G
      Not sure what your meaning or how to code this, not familiar with data::dumper
Re: Printing issue with an array
by Anonymous Monk on Apr 10, 2009 at 08:49 UTC
    When you say "When I view it from either the file or the php page", is this generating a html file?
    if so you need to use
    print "$name, $stime, $etime<br/>";
    Just a thought, a clearer answer with more context will give you a clearer answer that more precisely targets your question </rant>
      Yo this worked great, I can't believe the <br/>didn't cross my mind. So this did work so there is no confusion, print "$name, $stime, $etime<br/>"; And your slogan best descibes this issue. Thanks, Monk !!!