I think you can also do it this way if it makes more sense (someone correct me if I'm wrong, I can't test this here):
my $count = (readdir $dh); Which (again, correct me if I'm wrong) basically says "Assign the scalar value of the list whose elements are created by executing "readdir $dh" to the scalar $count". -----Original Message----- From: John W. Krahn [mailto:[EMAIL PROTECTED] Sent: Monday, June 16, 2003 11:00 AM To: [EMAIL PROTECTED] Subject: Re: Is empty directory? Jair Santos wrote: > > Thank to Mark , Rob and Charles for your help. > > I am using the following snippet of code to check if the directory is empty > and it is working. But I still cannot understand the line my $count = () = > readdir $dh; > > Can anybody explain whats the use of the = ( ) = ? readdir() returns a list in list context or a scalar in scalar context. In order to get the number of files you have to assign the list from readdir() to an array and then use that array in scalar context to get the number of elements of that array. my @array = readdir $dh; my $count = @array; But perl has a shortcut that allows you to assign a list to () which in scalar context returns the number of elements in the list without having to create an array. # with explicit array my $count = my @array = readdir $dh; # perl shortcut with no array my $count = () = readdir $dh; John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]