Powered by Ajaxy
Digg StumbleUpon LinkedIn YouTube Flickr Facebook Twitter RSS Reset

Perl: Creating a temporary file

use File::Temp qw(tempfile);
# Create temporary file
($fh, $fileName) = tempfile( );

Perl: Treating files in binary mode

open (FILEHANDLE, ">c:/test.txt")
    or croak ("Opening Failed");
print FILEHANDLE "Welcom to perl.tubedir.com";

Perl: How to modify the read, write, and execute permissions on a file.

#! /usr/local/bin/perl
chmod(0400, $file_1);  
chmod(0200, $file_1);  
chmod(0001, $file_1);

Perl: Copy a binary file

open file_src, "c:/icon2.gif"; 
binmode( file_src );
binmode( file_dest );
while ( read( file_src, $buffer, 1024 ) )
    print file_dest $buffer;

Perl: Change the owner and group of a list of files

$ uid=9496;
$ gid=40;
$number=chown($uid, $gid, 'test.vim', 'you.vim');

Perl: Open file for reading, writing, or updating

# Read only
open(FILEHANDLE, "", $path)                                or die $!;
sysopen(FILEHANDLE, $path, O_WRONLY|O_TRUNC|O_CREAT)        or die

Perl: Copying or Moving a File

#! /usr/local/bin/perl
use File::Copy;
    or die "can't copy, : $!";
# Move the file under a new name

Perl: Reading files in a particular encoding

 # Open a file encoded in utf-8
open(FH, "< :encoding(UTF-8)", $file)
    or die "can't open $file: $!";

Perl: How to Copy a file

open file_src, "c:/data.txt";  # target file
while (defined($line = ))  #read source file
{                                     # line by line

Perl: PrograssBar Example

for (0..20) {
    print "."; sleep 1;

Perl: Reading a Particular Line in a File

  #!/usr/bin/perl -w
  use Tie::File;
  use Fcntl;
  # Read Line 2
  @read_argv = ('c:/test.txt', 2)
  	or die "Error";
  ($filename, $line_number) =

Perl: Directory File Listing using opendir

chdir '..';                          #Current Directory
# Open
opendir(Dir, '.')
    or die "Unable to open directory.";
# List files
print join (',

Perl: Rename or delete a file/directory

# Rename the file
# Delete the file
	or die "Unable to delete $rep: $!";

Perl: Counting Lines in a File

open(FILE, ";
print "$file contains ",$count," lines";