I took everyone's advise and understood.  thank you!   The code ###- - -###
solved it!   Now for an explanation:
during the while loop,  the $_ contains return code such as:

ANS8000I Server command: 'tsm:select count(*) from nodes'
ANR1699I Resolved TSM to 2 server(s) - issuing command SELECT  against
server(s).
ANR1687I Output for command 'SELECT ' issued against server TSMSRV2
follows:

 Unnamed[1]
-----------
        356
ANR1688I Output for command 'SELECT ' issued against server TSMSRV2
completed.
ANR1687I Output for command 'SELECT ' issued against server TSMSRV1
follows:

 Unnamed[1]
-----------
        104
ANR1688I Output for command 'SELECT ' issued against server TSMSRV1
completed.
ANR1694I Server TSMSRV1 processed command 'SELECT ' and completed
successfully.
ANR1694I Server TSMSRV2 processed command 'SELECT ' and completed
successfully.
ANR1697I Command 'SELECT ' processed by 2 server(s):  2 successful, 0 with
warnings, and
0 with errors.

ANS8002I Highest return code was 0.


So in my while loop I say if line not like ANS or ANR using operator !~
"ANR*" or "ANS*".
I did try operator ne and this did not remove these lines.  I then tried a
reg exp like
while (<FF>) {
      $_ = s/^ANS*/ /g
      $_ = s/^ANR*/ /g
}

and this did not remove all these garbage lines.  I then tried
if (!/^ANS/ or !/^ANR/ )

and these lines were still printed.  So my solution was  if ( $_ !~ "ANR*"
or $_ !~ "ANS*" ).


I think this code is really cool and seems to be some type of trick?  I
looked in my learning perl and programming perl books and did not find this
code as below.  I then noticed in another email thread that  ##*##  was
used.  Are these related?  Where can I find documentation on these?


An explanation of the line marked with ###--###:

The regex searches for lines beginning with space(s), followed by at least
one
number before the line end. If this matches, the part after "and" is
executed, which sums up the number read into $total.

thank you,
derek

Derek B. Smith
OhioHealth IT
UNIX / TSM / EDM Teams




                                                                           
             John Doe                                                      
             <security.departm                                             
             [EMAIL PROTECTED]>                                              To 
                                       beginners@perl.org                  
             03/05/2005 01:25                                           cc 
             PM                        [EMAIL PROTECTED]              
                                                                   Subject 
                                       Re: reg exp                         
             Please respond to                                             
             security.departme                                             
                [EMAIL PROTECTED]                                               
 
                                                                           
                                                                           
                                                                           




Hi Derek

> #!/usr/bin/perl
>
> ## Set pragmas (LC) and modules (UC)
>
> $^W = 1;
> use strict;
> use strict 'subs';
>
> ## Begin Logic
>
> $ENV{"PATH"} = qq(/home/root:/usr/bin:/usr/sbin);
>
> my $w="40";
> my $total="0";
> my $outfile1 = qq(/home/root/tsm2_clients.out);
> my $outfile2 = qq(/home/root/tsm2_clients.plout);
> open (FF, "+<$outfile1") || die "could not open file: $outfile1 $!";
> open (FFF, "+<$outfile2") || die "could not open file: $outfile2 $!";
> system qq(dsmadmc -id=admin -password=st0rm "tsm:select node_name from
> nodes > $outfile1"
> );
> system qq(dsmadmc -id=admin -password=st0rm "tsm:select count(*)
node_name
> from nodes >> $
> outfile1" );

I don't know exactly what you want to achieve.

Maybe your code above produces the outputfile "tsm2_clients.plout"
mentioned
in the top post (i have no idea about dsmadmc; if this is important, i cant

help you), and now you want to trie to sum up the two numbers at the end of

this file ("tsm2_clients.plout")

If so,

> # what happens when more nodes get added?

John Krahn's code (cited under the next code snippet) does exactly that,
independent from the number of nodes/lines in "tsm2_clients.plout".

>         while (<FF>) {
>             if ( $. > 6 ) {
>                 if ( $_ !~ "ANR*" or $_ !~ "ANS*" ) {
>                         print FFF $_;
>                          /^s+(\d+) $/ and $total +=$1;
>                 }
>             }
>         }
>         print "Total Nodes on TSM1 and TSM2: $total\n";

Still, line 3 in the above code looks strange.

> close (FF) or warn "error closing $outfile1: $!";
> close (FFF) or warn "error closing $outfile2: $!";
>
>
> I tried the code give by John Krahn as hightlighted and this did not
work.
> Thanks though... any other ideas?

I ran John's code:

bash-2.05b$ perl
use strict;
use warnings;
open FF, "<", "tsm2_clients.plout" or die $!;

my $total;
while ( <FF> ) {
     /^\s+(\d+)$/ and $total += $1; ###--###
     }
print "Total = $total\n";

close (FF) or warn $!;


# output:

Total = 460


An explanation of the line marked with ###--###:

The regex searches for lines beginning with space(s), followed by at least
one
number before the line end. If this matches, the part after "and" is
executed, which sums up the number read into $total.

maybe $total could be initialized while declared, just for the case that
the
file is empty (which would produce a warning "Use of uninitialized value in

print...":
my $total=0; # instead of just my $total;


I just saw Charles's anwer with a bunch of good tips I did not mention to
keep
short.

greetings joe

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>





-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>


Reply via email to