I am trying to get the file using command-line argument such as "$>datafile -s filename "but unfortunately it is not working. The errors i am getting as below and only print out the first word for each line in the data file. Anyone know this easy stuff please help me to correct the code that i code wrong. I am trying to do command line checking on is "-s" specified, and the filename specified. If "-s" was specified, then set a true/false variable. If a filename was specified,then connect file to STDIN. Here is my code and errors. Please help! I searched on the net but no luck to get what i am want. Therefore, I need you guys expert help.
Thank you and cheer!
Best
Always
#textfile is data file
!/usr/bin/perl -w
$textfile = <~/bin/textfile>
$simple=0;
if ($ARGV[0] eq "-s")
{
$simple=1;
}
if ($simple)
{
do something with the record.\n";
}
if ($ARGV[0])
{
open (STDIN, "<$textfile") || die "Cannot open file $textphone,\n$!";
print "Opened file $textfile ok.\n";
}
while ($data =<STDIN>)
{
chomp $data;
print "$data";
}
TESTING USING THIS COMMAND textphone -s testing
/users/bin/textfile: line 1: What: command not found
/users/bin/textfile: line 2: The: command not found
/users/bin/textfile: line 4: you: command not found
/users/bin/textfile: line 5: or: command not found
/users/bin/textfile: line 6: people: command not found
/users/bin/textfile: line 7: syntax error near unexpected token `678-1255.'
/users/bin/textfile: line 7: `(575)456-3425. (459)-788-1054 as a phone number,'
IF I USE THIS COMMAND ./testing OR testing
Unquoted string "record" may clash with future reserved word at /users/bin/testing line 19.
Unquoted string "n" may clash with future reserved word at /users/bin/testing line 19.
String found where operator expected at /users/bin/testing line 24, near "open (STDIN, ""
(Might be a runaway multi-line "" string starting on line 19)
(Missing semicolon on previous line?)
String found where operator expected at /users/bin/testing line 24, near "$textfile") || die ""
(Missing operator before ") || die "?)
Bareword found where operator expected at /users/bin/testing line 24, near "") || die "Cannot"
(Missing operator before Cannot?)
String found where operator expected at /users/bin/testing line 25, near "print ""
(Might be a runaway multi-line "" string starting on line 24)
(Missing semicolon on previous line?)
Bareword found where operator expected at /users/bin/testing line 25, near "print "Opened"
(Do you need to predeclare print?)
Bareword found where operator expected at /users/bin/testing line 25, near "$textfile ok"
(Missing operator before ok?)
Unquoted string "ok" may clash with future reserved word at /users/bin/testing line 25.
Unquoted string "n" may clash with future reserved word at /users/bin/testing line 25.
String found where operator expected at /users/bin/testing line 32, near "print ""
(Might be a runaway multi-line "" string starting on line 25)
(Missing semicolon on previous line?)
Scalar found where operator expected at /users/bin/testing line 32, near "print "$data"
(Do you need to predeclare print?)
String found where operator expected at /users/bin/testing line 32, at end of line
(Missing semicolon on previous line?)
syntax error at /users/bin/testing line 19, near "do something with the "
Can't find string terminator '"' anywhere before EOF at /users/bin/testing line 32.