I need help with the following script. Im stuck. I need to replace anywhere it says SYNTAX or INDEX with the appropriate code but Im not sure what is right. Any suggestions would be great. thanks
#!/usr/bin/perl -w
########################################
# Script name: linenum.pl
# Functionality: This script requires that the command line argument # be a file. The file will be opened and each statement will be output to
# stdout in the following format: # Input format: Line number : Program # statement
# e.g. 22 : if ( $readme -eq $base )
# Case #1: ./linenumber printnum.sh
#######################################
# Handles the enforcement of correct number of arguments
unless (SYNTAX){
print "error: incorrect number of arguments",
"\n",
"usage: linenum [filename]",
"\n";
exit 1;
}
# Opens file from argument
open(MY_FILE, "$ARGV[INDEX]") or die
"error: argument must be a file\n",
"usage: linenum [filename]\n$!\n";
# Checks if file is a directory
if (-SYNTAX "$ARGV[INDEX]"){
print "error: argument must be a file",
"\n",
"usage: linenum [filename]\n";
exit 1;
}
$COUNTER=1; # Used for printing line numbers
# Loop and writes lines from file
SYNTAX ($LINE=<MY_FILE>){
# Adds leading zeros for numbers 1 digit long
if ($COUNTER<10){
print "000";
}
# Adds leading zeros for numbers 2 digits long
if (($COUNTER>9) && ($COUNTER<100)){
print "00";
}
# Adds leading zeros for numbers 3 digits long
if (($COUNTER>99) && ($COUNTER<1000)){
print "0";
}
# Prints line number and line
print "$COUNTER: $LINE";
$COUNTER+=1;
}
exit 0;
#!/usr/bin/perl -w
########################################
# Script name: linenum.pl
# Functionality: This script requires that the command line argument # be a file. The file will be opened and each statement will be output to
# stdout in the following format: # Input format: Line number : Program # statement
# e.g. 22 : if ( $readme -eq $base )
# Case #1: ./linenumber printnum.sh
#######################################
# Handles the enforcement of correct number of arguments
unless (SYNTAX){
print "error: incorrect number of arguments",
"\n",
"usage: linenum [filename]",
"\n";
exit 1;
}
# Opens file from argument
open(MY_FILE, "$ARGV[INDEX]") or die
"error: argument must be a file\n",
"usage: linenum [filename]\n$!\n";
# Checks if file is a directory
if (-SYNTAX "$ARGV[INDEX]"){
print "error: argument must be a file",
"\n",
"usage: linenum [filename]\n";
exit 1;
}
$COUNTER=1; # Used for printing line numbers
# Loop and writes lines from file
SYNTAX ($LINE=<MY_FILE>){
# Adds leading zeros for numbers 1 digit long
if ($COUNTER<10){
print "000";
}
# Adds leading zeros for numbers 2 digits long
if (($COUNTER>9) && ($COUNTER<100)){
print "00";
}
# Adds leading zeros for numbers 3 digits long
if (($COUNTER>99) && ($COUNTER<1000)){
print "0";
}
# Prints line number and line
print "$COUNTER: $LINE";
$COUNTER+=1;
}
exit 0;