Read the contents of file and read contents of a directory using Perl Script
#!c:\perl64\bin\perl.exe -w
while(<FILE>)
{
print <FILE>;
}
close(FILE);
#open a directory and read the contents of directory
#!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"; }
No comments:
Post a Comment