
Laurent_R
Veteran
/ Moderator
Oct 2, 2012, 12:35 AM
Post #3 of 3
(2001 views)
|
Re: [lie soul] Help with perl code that i'm trying to work with!
[In reply to]
|
Can't Post
|
|
Hi, there are a number of errors or inconsistencies in your code. Just to point out a few:
my $file = $ARGV[0]; $file = "student_list.txt"; Either you want to pass the file name as an argument to the program (first line) or you want it hard-coded (second line), but it does not make sense to do both.
my $name = substr(index()); my $ssn = substr(index()); my $type = substr(index()); index is a bare word, it should probably be $index. In addition, it has not be properly initialized, it is undefined at this point in the code. The substr function probably needs two or three arguments (check the documentation). And, anyhow, the substr function is not adapted to your problem, since you do not know how long the first field (first name, middle name, last name) will be. You probably need to split your input line on the separator (/).
my $first = substr my $middle = substr my $last = substr This obviously will not compile, as the syntax for the substr is not respected and the semi-colons are missing.
my $id = lc() . lc() . lc(); The lc function needs an argument.
while(<IN>) { my $passwd = <STDIN>; my $line = $_; It is probably better to obtain the password from the user before starting the while loop on the file. Something like this:
my $passwd = <STDIN>; while(my $line = <IN>) { #...}
|