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>


Reply via email to