Loading ...
Sorry, an error occurred while loading the content.
 

Re: [PBML] pass url vars to script

Expand Messages
  • merlyn@stonehenge.com
    ... bluechickidee How do I pass multiple, unknown variables to a script? You don t, not safely. Just do this: use CGI qw(param); Then param() gives you a list
    Message 1 of 3 , Nov 8, 2003
      >>>>> "bluechickidee" == bluechickidee <microsteel@...> writes:

      bluechickidee> How do I pass multiple, unknown variables to a script?

      You don't, not safely.

      Just do this:

      use CGI qw(param);

      Then param() gives you a list of all vars, and param("foo") gives
      you the value for var foo. In a scalar context, it gives the
      first value, and in a list context, it gives all values.

      If someone gives you a solution that "makes variables" from this
      DO NOT DO THAT. It's dangerous.

      --
      Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
      <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
      Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
      See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
    • Brad Lhotsky
      Yeah, use a hash. Instead of ?ghi=1234 making $ghi = 1234, you d do this: my %params = (); for(param()) { $params{$_}=param($_); } so now, $params{ghi} =
      Message 2 of 3 , Nov 10, 2003
        Yeah, use a hash. Instead of ?ghi=1234 making $ghi = 1234, you'd do
        this:

        my %params = ();
        for(param()) {
        $params{$_}=param($_);
        }

        so now, $params{ghi} = 1234;

        You also protect you script from unexpected behavior when a bad guy
        sends a variable that overwrites one or more of your or perl's variables.

        Using a hash also gives you access to exists() and keys() which are very
        effective and incredibly useful tools for managing which variables got
        passed. I never understood why ppl would want to have an unknown number
        of unknown variables set dynamically. How do you code for that?

        On Sat, Nov 08, 2003 at 01:50:54PM -0800, merlyn@... wrote:
        > >>>>> "bluechickidee" == bluechickidee <microsteel@...> writes:
        >
        > bluechickidee> How do I pass multiple, unknown variables to a script?
        >
        > You don't, not safely.
        >
        > Just do this:
        >
        > use CGI qw(param);
        >
        > Then param() gives you a list of all vars, and param("foo") gives
        > you the value for var foo. In a scalar context, it gives the
        > first value, and in a list context, it gives all values.
        >
        > If someone gives you a solution that "makes variables" from this
        > DO NOT DO THAT. It's dangerous.
        >
        > --
        > Randal L. Schwartz - Stonehenge Consulting Services, Inc. - +1 503 777 0095
        > <merlyn@...> <URL:http://www.stonehenge.com/merlyn/>
        > Perl/Unix/security consulting, Technical writing, Comedy, etc. etc.
        > See PerlTraining.Stonehenge.com for onsite and open-enrollment Perl training!
        >
        >
        > Unsubscribing info is here: http://help.yahoo.com/help/us/groups/groups-32.html
        >
        > Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        >
        >

        --
        Brad Lhotsky <brad@...>
      Your message has been successfully submitted and would be delivered to recipients shortly.