Click here to Skip to main content
15,312,353 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have the below code how can i read the contents from the text file and check with directories and sub directories names exists or not using perl.

Note:result_file.txt has contents.Each contents denotes the directories/subdirectories in the current location.

What I have tried:

<pre>open( my $fh2, '<', "result_file.txt" ) || die( $! ))
while ( my $row = <$fh2> ) {
	chomp $row;
	my $dir = $row;
      print $dir,"\n";
	#print "****$row****";
Updated 21-Feb-17 21:10pm

1 solution

See the file test operations at perlfunc - Perl builtin functions -[^].

use Cwd;

my $curdir = cwd();
if (-e $dir && -d $dir)
    print "$dir is an existing directory at $curdir\n";

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900