Posted by: saisjsu | May 3, 2008

File handling in Perl

Here is the basic perl program which does the same as the UNIX cat command on a certain file.

#!/usr/local/bin/perl
#
# Program to open the password file, read it in,
# print it, and close it again.

$file = '/etc/passwd';		# Name the file
open(INFO, $file);		# Open the file
@lines = <INFO>;		# Read it into an array
close(INFO);			# Close the file
print @lines;			# Print the array

Leave a response

Your response:

Categories