Thursday, October 1, 2015

Read the contents of file and read contents of a directory using Perl Script

Read the contents of file and read contents of a directory using Perl Script


#!c:\perl64\bin\perl.exe -w
use strict;

use warnings;



my $filePath = "F:\\Perl\\Perl\\testfile.txt";

open(FILE,"$filePath") or die "couldn't open the file, $!";

#Reading the Complete file (Slurping) and printing the content
while(<FILE>)
{
print <FILE>;
}
close(FILE);

#open a directory and read the contents of directory

my $dir = "F:\\Perl\\Perl\\*";

my @files = glob($dir) or die "Couldn't open the directory, $!";

foreach (@files)

{

print $_ . "\n";

}

Read contents of file and directory
Read contents of file and directory

No comments:

Post a Comment