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

This is a repost for Swiftone, who was very helpful yesterday in putting me on the path to solving my problem. I am reposting it because I don't have it solved yet and he seemed to understand what I was trying to do......

*******************************************************

I changed the qx to qq and displayed the string as it is built. The result was exactly as I expected. I even cut and paste the generated string on the command prompt and it executed with the expected results. Here is the generated string: aml_read /l trace /h FTWAEIPD0001 /s "12/04/2000 07:00:00" /b "12/04/2000 08:00:00" /d all /appl commproc | egrep -c -e tty2

....Which once again should be generated from this:

$tty = qx{aml_read /l trace /h $_[3] /s $_[1] /b $_[2] /d all /appl c +ommproc | egrep -c -e $tty_string}; printf("<TR ALIGN=LEFT VALIGN=TOP>\n"); printf("<TD>%s</TD>\n",$tty_string); chomp($tty); printf("<TD>%d</TD>\n",$tty); printf("</TR>\n");

What is also weird is that I can hardcode the variables in the query and get the same results (although it seems to only work outside the loop). I suppose it is possible that I have more than one problem. One problem could be the qx line and the loop may also have errors.

Thanks Bryan

Replies are listed 'Best First'.
Re: for SWIFTONE
by swiftone (Curate) on Dec 05, 2000 at 20:33 UTC
    Wow, I've never had my very own dedicated thread before :)

    Anyway, let's see if we can work on this. I can't provide code, since I don't have your aml_read program, nor your datafile.

    You mentioned (elsewhere), that this problem only began to show up when you changed OS's. That could me that either you've got a screwy version of perl (unlikely), a screwy shell (who knows?), or a messed up environment.

    I guess we just start debugging. You've established that the line by itself works, with variables hardcoded. That would seem to say that it's either a problem with interpolation of the qx{}, or a logical error in the loop.

    Step One: Leaving everything the same in the program, replace the $_[?] variables with some content (leave the loop intact). If that doesn't run, it means the problem is not the qx{}, but the loop. (You haven't shown us the loop, so we can't debug it)

      Man, I love this! The play by play of a debug session! This is the Matrix meets that bloody burning tower movie which name I can't remember right now.

      Go Swiftone!

      I can picture you, calm, in control, getting in the zone, hitting the Reload button, quickly typing an answer, then relaxing, leaning back in your chair and sipping your Diet Coke while planning the next move, evaluating all possibilities but in your heart you know that eventually you will prevail.

      Meanwhile Motley is sweating, swearing as he made yet another typo, praying for the next answer to come back before this darn qx{} loop crashes again, sweat beads roll from his forefront, empty pizza boxes and half-empty coffee cups litter the floor...

      Man... why don't they release more movies like this!

      I can't wait for the next episode: "The Loop".

      Sorry...

      Update: I misread the label, Swiftone only drinks regular Coke, sorry once again.

      Thanks for your help Swiftone.

      Ok, here's what I've done. I copied the aml_read line with hardcoded variables inside the loop and it didn't work. Then I put the same line before the loop and it seemed to work. Here is what the code looks like right now including what's commented out with the =cut:

      =cut $tty = qx{aml_read /l trace /h ftwaeipd0001 /a commproc /s "12/04/2 +000 07:00:00" /b "12/04/2000 08:00:00" /d all | egrep -c -e tty2}; =cut for ($i = $TTYFIRST; $i <= $TTYLAST; $i++) { Tty_check($i,$start_ts,$end_ts,$selectedserver); } sub Tty_check { $tty_string = sprintf( "tty%d", $_[0] ); =cut $tty = qx{aml_read /l trace /h $_[3] /a commproc /s $_[1] /b $_[2] + /d all | egrep -c -e $tty_string}; =cut $tty = qx{aml_read /l trace /h ftwaeipd0001 /a commproc /s "12/04/2 +000 07:00:00" /b "12/04/2000 08:00:00" /d all | egrep -c -e tty2}; printf("<TR ALIGN=LEFT VALIGN=TOP>\n"); printf("<TD>%s</TD>\n",$tty_string); chomp($tty); printf("<TD>%d</TD>\n",$tty); printf("</TR>\n"); }

      So it does appear that there is a problem with the loop, although yesterday I displayed the contents with the qq instead of qx inside the loop and got what I was expecting. What next?

        What next?

        Good question. I'm somewhat stumped...inside or outside of the loop, it should work the same way. Here's the code I tried (I used echo '' ) around it since I don't have aml_read)

        #!/usr/bin/perl -w use strict; my $TTYFIRST = 2; my $TTYLAST = 17; my $start_ts = '"12/04/2000 07:00:00"'; my $end_ts = '"12/04/2000 08:00:00"'; my $selectedserver = 'ftwaeipd0001'; for (my $i = $TTYFIRST; $i <= $TTYLAST; $i++) { Tty_check($i,$start_ts,$end_ts,$selectedserver); } sub Tty_check { my $tty_string = 'tty'.$_[0]; my $tty = qx{echo 'aml_read /l trace /h $_[3] /a commproc /s $ +_[1] /b $_[2] /d all | egrep -c -e $tty_string'}; chomp($tty); print "<TR ALIGN=LEFT VALIGN=TOP>\n"; print "<TD>$tty_string</TD>\n"; print "<TD>$tty</TD>\n"; print "</TR>\n"; }
        And it appear to do the Right Thing. Does it for you?

        If so, how about trying to replace the big command with a smaller one. Try just running egrep on a file, or aml_read without piping through egrep. (Still do all of this inside the loop.) I'm guessing now, because this code should work.