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:34 AM, Emeka <emekami...@gmail.com> wrote: > 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 > > > * >