Find the answer to your Linux question:
Results 1 to 2 of 2
Hello Here is the chunk of code that doesn't want to work with me: Code: #!/usr/bin/perl -wT use strict; use CGI::Carp qw(warningsToBrowser fatalsToBrowser); use CGI qw/:standard/; my $media_type = param('media_type'); ...
  1. #1
    Just Joined! vitalka's Avatar
    Join Date
    Oct 2004
    Location
    Toronto, ON
    Posts
    77

    [SOLVED] problems with subroutines

    Hello
    Here is the chunk of code that doesn't want to work with me:
    Code:
    #!/usr/bin/perl -wT 
     
    use strict; 
    use CGI::Carp qw(warningsToBrowser fatalsToBrowser); 
    use CGI qw/:standard/; 
     
     
    my $media_type = param('media_type'); 
     
     
    print header; 
    print start_html('New Order'),"New Order"; 
    print start_form(-method=>'get'); 
     
     
    if ($media_type == "film"){ 
            &film_form(); 
     
    } elsif ($media_type == "tapes"){ 
            &tapes_form(); 
     
    } elsif ($media_type == "sildes/photo"){ 
            &slides_form(); 
     
    } elsif ($media_type == "audio-tapes"){ 
            &tapes_form(); 
     
    } else { 
            &media_type_form(); 
    } 
     
     
    print end_form; 
    print end_html; 
     
     
    #------------------------------------------------------- 
    #------------------------------------------------------- 
    # allow to select media type 
     
    sub media_type_form 
    { 
    print "Media Type: ", 
            scrolling_list('media_type', 
            ['','film','tapes','slides/photo','audio-tapes'], 
            -size=>1), 
            br, 
            submit(-name=>'select',-value=>'select'); 
    } 
     
    #------------------------------------------------------- 
    #------------------------------------------------------- 
    # displays form for FILM media 
     
    sub film_form 
    { 
    print "FILM FORM"; 
    } 
     
    #------------------------------------------------------- 
    #------------------------------------------------------- 
    # displays form for TAPES media 
     
    sub tapes_form 
    { 
    print "TAPES FORM"; 
    } 
     
    #------------------------------------------------------ 
    #------------------------------------------------------- 
    # dispplays form for SLIDES/PHOTOS 
     
    sub slides_form 
    { 
    print "TAPES FORM"; 
    } 
     
    #------------------------------------------------------- 
    #------------------------------------------------------- 
    # displays form for AUDIO tapes 
     
    sub audio_form 
    { 
    print "AIDIO TAPES FORM"; 
    } 
     
     
    #------------------------------------------------------- 
     
    __END__

    When I run it I get the following;
    Code:
    New Order 
    FILM FORM
    When it runs for the first time its suppose to give a select menu to choose media type, but instead it thinks that FILM media was selected.

    Can any one help me?

    Thank you.

  2. #2
    Just Joined! vitalka's Avatar
    Join Date
    Oct 2004
    Location
    Toronto, ON
    Posts
    77
    Well I solved this by replacing '==' with 'eq'.
    Code:
    if ($media_type == "film"){ 
            &film_form(); 
     
    } elsif ($media_type == "tapes"){ 
            &tapes_form(); 
     
    } elsif ($media_type == "sildes/photo"){ 
            &slides_form(); 
     
    } elsif ($media_type == "audio-tapes"){ 
            &tapes_form(); 
     
    } else { 
            &media_type_form(); 
    }

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...