-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_handle.pl
52 lines (38 loc) · 866 Bytes
/
file_handle.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#read mode (<)
#write mode (>)
#append mode (>>)
#syntax ---> open(filehandle,mode,filename)
my $filename = 'perl.txt';
#opening the files in the read modes
open(FH, '<', $filename) or die $!;
print("file $filename opend successfully!\n");
#reading a file line by line
while(<FH>){
print("$_");
}
#opening file in the wriete mode
my $str = <<END;
hi this is subham
END
open(FH,'>',$filename) or die $!;
print(FH "$str");
print("writting succesfully!\n");
#reading a file line by line
while(<FH>){
print("$_");
}
my $src = 'demo.pl';
my $des = 'last.pl';
# open source file for reading
open(SRC,'<',$src) or die $!;
# open destination file for writing
open(DES,'>',$des) or die $!;
print("copying content from $src to $des\n");
while(<SRC>){
print DES $_;
}
# always close the filehandles
close(SRC);
close(DES);
#close the file
close(FH);