I guess that $sum should be "my $sum" before using it.

Emeka

On Mon, Aug 1, 2011 at 8:26 AM, John W. Krahn <jwkr...@shaw.ca> wrote:

> homedw wrote:
>
>> hi all,
>>
>
> Hello,
>
>
>
>  i want to open some tha files in a directory, you can see the details
>> below,
>>
>> #!/usr/bin/perl -w
>> use strict;
>> opendir (FH,'C:\Player');
>> chdir 'C:\Player';
>> for my $file(readdir FH)
>> {
>>         open DH,"$file";
>>         foreach my $line(<DH>)
>>         {
>>                 while($line=~/"a=(\d),b=(\w+)"**/gi)
>>                 {
>>                 $sum+=$2-$1;
>>                 }
>>          }
>> }
>> print "$sum\n";
>>
>>
>> I can't open the files in 'C:\Player', can you help me find out where the
>> problem is?
>>
>
> Use error checking on your system calls and let the system tell you what
> the problem is:
>
>
> #!/usr/bin/perl
> use warnings;
> use strict;
>
> opendir FH, 'C:\Player' or die "Cannot opendir 'C:\\Player' because: $!";
> chdir 'C:\Player' or die "Cannot chdir to 'C:\\Player' because: $!";
>
>
> for my $file ( readdir FH )
> {
>        open DH, '<' $file or die "Cannot open '$file' because: $!";
>
>        foreach my $line ( <DH> )
>        {
>                while ( $line =~ /"a=(\d),b=(\w+)"/gi )
>                {
>                $sum += $2 - $1;
>                }
>         }
> }
> print "$sum\n";
>
> __END__
>
>
>
> John
> --
> Any intelligent fool can make things bigger and
> more complex... It takes a touch of genius -
> and a lot of courage to move in the opposite
> direction.                   -- Albert Einstein
>
> --
> To unsubscribe, e-mail: beginners-unsubscr...@perl.org
> For additional commands, e-mail: beginners-h...@perl.org
> http://learn.perl.org/
>
>
>


-- 
*Satajanus  Nig. Ltd


*

Reply via email to