Question
Write a Perl script that prints the contents of a file, prefixing each line with a line number. The script should accept exactly one argument
Write a Perl script that prints the contents of a file, prefixing each line with a line number. The script should accept exactly one argument representing the name of the file.
The script should be able to handle the following error conditions:
o Incorrect number of arguments
o The specified argument is not a file.
You cannot use the UNIX cat command in this assignment. You must use Perl to read the file and count the lines.
You cannot use the UNIX nl command in this assignment.
The printf function in Perl is useful for formatting numbers.
The script file name must be: linenum.pl
The script must be located in $HOME/itec400/homework
Make sure the permissions on the your itec400 directory are 705
Make sure the permissions on your script are 705
***Please use the template below***
Sample Output Sunny Day Scenario: > linenum.pl /export/home/dandrear/public_html/itec400/examples/ex0330 0001: #!/bin/perl -w 0002: 0003: # # # # # # # # # # # 0004: # File: ex0330 0005: # 0006: # A simple Perl script that demonstrates 0007: # the use of hash (plural) variables 0008: ########### 0009: 0010: %states 1 = ( "oh", "Ohio", "fl", "Florida", 0011: "de", "Delaware" ); 0012: print "I live in $states_1{oh} "; 0013: 0014: $states_2 =( 0015: "oh" => "Ohio", 0016: "f1" => "Florida", 0017: "de" => "Delaware" 0018: ); 0019: print "I was born in $states 2{de} "; Rainy Day Scenarios: > linenum.pl error: program must be executed with 1 argument. usage: linenum.pl filename > linenum.pl a b error: program must be executed with 1 argument. usage: linenum.pl filename > linenum.pl /etc error: argument must be a file usage: linenum.pl filename #!/usr/bin/PROGRAM STATEMENT # Script name: linenum.pl # Case #1: ./linenum.pl
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started