Satanya has asked for the wisdom of the Perl Monks concerning the following question:
I am seeking the wisdom of the perl monks...
For some reason I don't know why my code does not work. I have commented on the lines that are giving me a problem.
If anyone could give me any insight I would love it.
Thanks agian for your time.
Satanya
"Dadis_Ramsey_lab4.pl" 193 lines, 5620 characters #!/usr/bin/perl print "This program is designed to sort files containing a list of:\n" +; print "First Names, Last Names, Ages, Sexes, Heights, and Weights\n"; $inputfile = "lab4.txt.33"; openfile(); sub Menu { print "\nHere is a list to select from:\n"; print "A. Set input filename\n"; print "B. Load file\n"; print "C. Sort by Last Name\n"; print "D. Sort by First Name\n"; print "E. Sort by Age\n"; print "F. Sort by Height\n"; print "G. Sort by Weight\n"; print "Q. Quit\n"; print "Enter your Selection: "; chomp ( $selec = <STDIN> ); $selec =~ s/[a-z]/[A-Z]/; } if ( $selec eq 'A' ) { namefile(); Menu (); } elsif ( $selec eq 'B' ) { openfile(); } elsif ( $selec eq 'C' ) { sortlast(); Menu(); } elsif ( $selec eq 'D' ) { sortfirst(); Menu(); } elsif ( $selec eq 'E' ) { sortage(); Menu(); } elsif ( $selec eq 'F' ) { sortsex(); Menu(); } elsif ( $selec eq 'G' ) { sortheight(); Menu(); } elsif ( $selec eq 'H' ) { sortweight(); Menu(); } elsif ( $selec eq 'I' ) { print "\n\nGood Bye..."; exit; } else { print "You have entered an invalid selection.\n"; print "Please try again:\n"; Menu (); } while ( <File> ) { chomp; ( $last, $first, $age, $sex, $height, $weight, $comment ) = split (/,/); push( @last, $last); push( @first, $first); push( @age, $age); push( @sex, $sex); push( @height, $height); push( @weight, $weight); push( @comment, $comment); } sub sortage() { $num = @age; for ( $i = 0; $i <= $num; i++) { # something is wrong her +e for($j = $i+1; $j = $num; $j++) { # and here if ( $age[$i] > $age[$j] ) { @age[$i,$j] = @age[$j,$i]; @last[$i,$j] = @last[$j,$i]; @first[$i,$j] = @first[$j,$i]; @sex[$i,$j] = @sex[$j,$i]; @height[$i,$j] = @height[$j,$i]; @weight[$i,$j] = @weight[$j,$i]; @comment[$i,$j] = @comment[$j,$i]; } # And here } } } sub openfile( ) { open ( File, $inputfile) || die "failure: $!"; @file = < File >; close ( File ); Menu (); } sortlast() { $num = @last; for ( $i = 0; $i <= $num; $i++) { for($j = $i+1; $j = $num; $j++) { if ( $last[$i] > $last[$j] ) { @age[$i,$j] = @age[$j,$i]; @last[$i,$j] = @last[$j,$i]; @first[$i,$j] = @first[$j,$i]; @sex[$i,$j] = @sex[$j,$i]; @height[$i,$j] = @height[$j,$i]; @weight[$i,$j] = @weight[$j,$i]; @comment[$i,$j] = @comment[$j,$i]; } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Please help...not certain why my code does not work.
by srawls (Friar) on Jun 05, 2001 at 00:42 UTC | |
by Satanya (Novice) on Jun 05, 2001 at 00:53 UTC | |
|
Re: Please help...not certain why my code does not work.
by arturo (Vicar) on Jun 05, 2001 at 00:12 UTC | |
by Satanya (Novice) on Jun 05, 2001 at 00:47 UTC | |
|
Re: Please help...not certain why my code does not work.
by suaveant (Parson) on Jun 05, 2001 at 00:05 UTC | |
by Satanya (Novice) on Jun 05, 2001 at 00:43 UTC |