Search for Tips & Tricks

Google
 
Showing posts with label Perl. Show all posts
Showing posts with label Perl. Show all posts

Friday, January 18, 2008

How to create/Delete a directory tree

>>>>>>>>>>>>>>>>>> Code >>>>>>>>>>>>>

user File::Path;

mkpath('Level1/Level2/Level3'); # Create all directories tree Level1-->Level2-->Level3

rmtree('Level1/Level2/Level3'); # Delete all directory tree

Thursday, January 10, 2008

How to return reference to a File Handle from Subroutine

>>>>>>>>>>>>>>> Code >>>>>>>>>>>
my $FH = returnFileHandle();

print $FH "Hello, World";

sub returnFileHandle {

my $fileName = "file.txt";

open (FILEHANDLE, ">$fileName") or die $!;

return \*FILEHANDLE;

}

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
The subroutine returnFileHandle() returns file handle (in overwrite mode) of file "file.txt".

Thursday, January 3, 2008

How to delete files in Perl ?

>>> Code >>>>>>

@fileList = (”file1.txt”,”file2.pl”,”file3.java”);

unlink @filelist;

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

The above code will delete files in fileList arry from current directory. If you want to remove files from a specific directory first use “chdir ” to set the present directory and then user unlink.