CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
Help with perl code that i'm trying to work with!

 



lie soul
Novice

Oct 1, 2012, 3:46 PM

Post #1 of 3 (957 views)
Help with perl code that i'm trying to work with! Can't Post

Hello

Please see the attachment file, which is my guide to do this.. i just started my code and i need help.. this is my first try:

this is the code i created and i'm not there yet but i need help... i need help to tell me what i do next or add .. also if i did something wrong.


Code
#!/usr/bin/perl -w 
use strict;

my $file = $ARGV[0];
$file = "student_list.txt";

open IN, "$file" or die "Cannot read $file: $!\n";

my %ID;

while(<IN>)
{
my $passwd = <STDIN>;
my $line = $_;

my $name = substr(index());
my $ssn = substr(index());
my $type = substr(index());


my $first = substr
my $middle = substr
my $last = substr

$first = substr($first, 0, 1);
$middle = substr($middle, 0, 1);
$last = substr($last, 0, 1);

my $id = lc() . lc() . lc();

if ($type eq "....")
{


}
if ( exists $ID{$id})
{
next;
}
else
{

$ID{$id} = "$id:";
}

$passwd = &encrypt($passwd);
$ID{$id} = $ID{$id} . "$encrypted:"
$ID{$id} .= "$encrypted:"

{
}


I didn't attached the student_file.tx .. since you can create your own one..

I only attached the guide for this... help is appropriate it.

thanks
Attachments: guide.txt (3.17 KB)


FishMonger
Veteran / Moderator

Oct 1, 2012, 5:21 PM

Post #2 of 3 (953 views)
Re: [lie soul] Help with perl code that i'm trying to work with! [In reply to] Can't Post

Your script won't compile. Your first step is to troubleshoot and fix those compilation errors starting with the first one.

If you need assistance, ask a specific question at each point where you get stuck.


Laurent_R
Veteran / Moderator

Oct 2, 2012, 12:35 AM

Post #3 of 3 (942 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:



Code
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.


Code
	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 (/).


Code
	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.


Code
my $id = lc() . lc() . lc();


The lc function needs an argument.


Code
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:


Code
my $passwd = <STDIN>;  
while(my $line = <IN>)
{ #...}


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives