On Wed, 18 Sep 2002, James Parsons wrote:

> Ok since I'm new to Perl I've written this fairly simple script to add
> number from a text file, I have about 20-30 of these file with different
> names and I would like to know how to add this to my script, I know  how to
> do it  korn shell but in a perl script I'm really now sure, can  anyone
> point in the direction, Thanks for all your help..
> 
>

Wrap this script by this and use $file in your open call
perldoc -f glob
perldoc -f File::Glob
while (my $file = <mtd_temp*>) {
}
 
> script: 
> #!/usr/bin/perl -w
> 
> use strict;
> 
> my $total = 0;
> 
> open(FILE,"/usr/local/logs/onlines/mtd_temp") || die $!; # I have about 20
> mtd_temp1,2,3, etc                        
> $total += $_ while(<FILE>);

The line read in from <FILE> will come in along with newline. This works 
because the string when treated as a number considers only the initial 
numric part. For e.g. the string "123abc" when evaluated as a number is 
123, "12\n" as a number is 12. 
 
For a clean code I would still recommend you chomp $_ (perldoc -f chomp)

> 
> close(FILE);
> 
> my $value = 100;
> 
> $total = $total/$value;
> 
> printf  "\$$total\n",;
> 
> etrprodcrm1pri /usr/local/sbin #        


-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to