#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Texas, US
    Posts
    9
    Rep Power
    0
    I want to setup a single script that does multiple things. Is there anyway to do that?

    like if the script is called
    /cgi-bin/script.cgi
    it runs one subroutine, but if it's called
    /cgi-bin/script.cgi?something
    it runs a different subroutine.

    Thanks!
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2000
    Posts
    27
    Rep Power
    0
    Set up the script with a flag before any functions are reached.....then when linking to your script inclue the flags value when calling it......ie:

    your call----> "/cgi-bin/script.pl?your_flag=do_this"

    your script----->
    if ($your_flag eq 'do_this')
    {
    &do_subroutine
    }
    if ($your_flag ne 'do_this')
    {
    &do_main_function
    }

    hope that helps
  4. #3
  5. No Profile Picture
    chinnavi
    Guest
    Devshed Newbie (0 - 499 posts)

    you can parse the input given by calling this line first

    read(STDIN, $input, $ENV{'CONTENT_LENGTH'});

    this line will read the inputs ie suppose if call a cgi like this
    /cgi-bin/call.cgi?dothis

    then $input have "dothis" ..


    then u can use the previous logic
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Texas, US
    Posts
    9
    Rep Power
    0
    Thanks for the help, but neither method seems to work.
  8. #5
  9. No Profile Picture
    freebsd
    Guest
    Devshed Newbie (0 - 499 posts)
    >>but neither method seems to work

    Why not? You must have done something incorrectly to your script yourself.

    Anyway, try this example:

    #################################################
    #!/usr/local/bin/perl

    print "Content-type: text/htmlnn";

    if ($ENV{'QUERY_STRING'}) {
    &do_subroutine;
    }
    else {
    &do_main_subroutine;
    }

    sub do_subroutine {
    print "Hello World.n";
    print "The query string is "$ENV{'QUERY_STRING'}"n";
    }
    sub do_main_subroutine {
    print "Hello World.n";
    print "No query string. Do somethin else.n";
    }
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2000
    Location
    Texas, US
    Posts
    9
    Rep Power
    0
    That seems to work...Thanks, instead of trying to figure out why the first two didn't work I'm just using

    #######
    $input= $ENV{'QUERY_STRING'};


    [This message has been edited by jltumlinson (edited July 09, 2000).]

IMN logo majestic logo threadwatch logo seochat tools logo