Perl file and folder listing -Help

Hello,

I want to display all files and folders in a drive under windows. I tried two ways.
1-Way Here is the code snippet.
opendir DIR, "F:\"; # Searching under F drive
my @files = readdir(DIR); # Reading eveythg under F drive
closedir DIR; # closeing the directory handler
foreach my $file (@files) {
print "This is file $file \n" if (-f $file);
print "This is folder $file \n" if (-d $file);
}

Result :It is not listing anythg.I think it cant differentiate files and folders,It will work under UNIX not in WINDOWS .
2-Way Code snippet.
$value = "F:/*\.*"; # Searching under F drive
@files = <"$value">;
foreach my $file (@files) {
print "Here is the content of the drive $file ";
}

Result :Here nothg got displayed.
Please help..

Thanks in advance
Coolbhai

opendir DIR, "F:/"; # Searching under F drive
my @files = readdir(DIR); # Reading eveythg under F drive
closedir DIR; # closeing the directory handler
foreach my $file (@files) {
print "This is file $file \n" if (-f "f:/$file");
print "This is folder $file \n" if (-d "f:/$file");
}

You can use forward slashes with Windows for file and folder access.

Thanks KevinADC,
Could you solve the second script issue..

$value = "F:/*\."; # Searching under F drive
@files = <"$value">; # but if I hardcord as @files = <F:/*.
>; it works well.
foreach my $file (@files) {
print "Here is the content of the drive $file ";
}

Result :Here nothg got displayed. I am running under WINDOWS operating System.

Please help..

If you would run your perl scripts with warnings turned on as is always recommended you might have figured it out:

readline() on unopened filehandle at script line 3.

the construct <"$value"> which should really be <$value> is interpreted as a filehandle not a glob. It should be:

use warnings;
@files = <F:/*.*>; 
foreach my $file (@files) {
   print "Here is the content of the drive $file ";
}

If for some reason you must use a scalar in the glob you can do this:

use warnings;
$value = 'F:/*.*'; 
@files = <${value}>;
foreach my $file (@files) {
   print "Here is the content of the drive $file ";
}

But you should really be using the glob() function instead of the <> brackets:

use warnings;
$value = 'F:/*.*'; # Searching under F drive
@files = glob($value); # but if I hardcord as @files = <F:/*.*>; it works well.
foreach my $file (@files) {
   print "Here is the content of the drive $file ";
}

Thank you very much KevinADC,

All the issue got solved..

If possible can you tell me the difference between below two statements.

my $num =10;
my ${num} =10;

Thanks in advance
Coolbhai