Thanks, the reason I ask is because some how I have done something wrong. When at the programs menu if I were to input lets say "10" it some how returns as a 1 then it fails the test causing my display_menu_error sub to be executed with this error "ERROR: illegal option: 1 selected" some where along the line the 10 I give the program is changed:
I just can't see why it would be doing that to me like thatdb_connect(); #Connect to the database if needed while ( display_menu(), ( my $option = <> ) ) { print '$option before processing input: ' . $option # returns 10 $option = process_input($option); print '$option after processing input: ' . $option # returns 1 if ( ( $option !~ m{/^\d+$/}xms ) or ( $option <= 0 ) or ( $option > +10 ) ) { display_menu_error("ERROR: illegal option: $option selected\n"); next; } print_form() if $option == 1; print_edit() if $option == 2; db_remove() if $option == 3; db_fetch() if $option == 4; print_all() if $option == 5; print_report() if $option == 6; db_check() if $option == 7; leave_comment() if $option == 8; leave_donation() if $option == 9; if ( $option == 10 ) { $dbh->disconnect; print "Quitter...\n"; exit 0; } } ... sub process_input { # takes in information and loops through testing the input for valid a +lphanumeric characters. my @data = @_; for (@data) { chomp; s/^\s*//; # Have tried commenting out no change s/\s*$//; # Still somehow returns incorrect values } return @data; }
In reply to Re^4: Returning and passing data to and from subroutines
by vendion
in thread Returning and passing data to and from subroutines
by vendion
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |