in reply to Re: for SWIFTONE
in thread for SWIFTONE

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?

Replies are listed 'Best First'.
Re: Re: Re: for SWIFTONE
by swiftone (Curate) on Dec 05, 2000 at 21:28 UTC
    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.

      I've displayed and compared the lines inside the loop and outside and the strings from this statement look exactly the same: $tty = qx{aml_read /l trace /h ftwaeipd0001 /a commproc /s "12/04/2000 07:00:00" /b "12/04/2000 08:00:00" /d all | egrep -c -e tty2};

      I can change both statements to qq inside and outside the loop and it runs and displays the string. But as soon as I change it back to qx the one inside the loop fails....

      I guess maybe I should try a different route. Is there any way I can walk through the code as it is executing and see exactly what it is doing?

        Is there any way I can walk through the code as it is executing and see exactly what it is doing?

        Absolutely. See Using the Perl Debugger