Hi Jack,
Your code should work fine except for d following:
 1. your $sum used in the while loop is out of scope
   i.e declare it before your first for loop, and intialize to zero. As u
have it in your code.
 The last print statement will print nothing 'cos $sum is out of reach, so u
see nonthing!

2. with the "use strict" used you shld ve error message telling about global
symbol "$sum" required explicit package name. So, u shld also do my $sum.

3. You might also need to check your inner while loop.
  a.) \d ==> means digits, while \w+ ==> means one or more
characters(words), so I wonder why you are trying to perform arithematic  on
dem! [Pls correct me if am wrong! about what are trying to do],
  b.) You don't ve to put $line is a quote to match!

 Note: Apart from what I stated above, your code shld
work, cos I ve tried ur code to print out a large file in another drive and
it worked perfectly, after the correction stated above was used!
Regards

On Mon, Aug 1, 2011 at 8:09 AM, homedw <hom...@gmail.com> wrote:

> hi all,
>
> i want to open some 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?
>
> thanks,
> Jack
>

Reply via email to