Sei sulla pagina 1di 2


Develop a Perl script that sorts lines of the given file in reverse order, so the last line becomes
first and vice-versa. The script must have two command line arguments, the first is an input file
name and the second is an output file name. For input file check to have existing and readable
file, otherwise print error and exit program. For output file check to have non-existing file,
otherwise print error and exit.


open IN,"<$in" or die "Error Opening Input file: $!";
while (<IN>)
push (@content, $_);
close (IN);

print "Original Lines:\n";

print "@content\n";
for ($i=$#content; $i>=0; $i--)

print "\n";

print "Reversed Lines:\n";

open OUT, ">$out" or die "Error opening the file. $!";
print OUT @new_content;
print @new_content;
close (OUT);