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]; } } } }

In reply to Please help...not certain why my code does not work. by Satanya

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.