passing $cgi object in hash.

Discussion in 'Perl Misc' started by sam, Jan 10, 2005.

  1. sam

    sam Guest

    Hi,

    I would like to pass the $cgi object to a subroutine from a hash object,
    somehting like this:

    #!/bin/usr/perl -w

    use CGI;

    sub testing
    {
    my ($obj1ref, $obj2ref, $str1, $str2, $cgi) = @_
    $cgi->submit($str1.$str2);
    }

    $cgi = new CGI;

    test($obj1,$obj2, "my", "string", $cgi);

    Is it possible?

    Thanks
    Sam
    sam, Jan 10, 2005
    #1
    1. Advertising

  2. sam

    sam Guest

    sam wrote:

    > Hi,
    >
    > I would like to pass the $cgi object to a subroutine from a hash object,
    > somehting like this:
    >
    > #!/bin/usr/perl -w
    >
    > use CGI;
    >
    > sub testing
    > {
    > my ($obj1ref, $obj2ref, $str1, $str2, $cgi_hash) = @_
    > $cgi_hash->{'cgi'}->submit($str1.$str2);
    > }
    >
    > $cgi = new CGI;
    >
    > test($obj1,$obj2, "my", "string", $cgi);
    >
    > Is it possible?
    >

    Sorry, this is of course possible. I forgot pass it in a hash object
    like below:

    $cgi = new CGI;
    my %_hash = ('cgi' => $cgi);
    test($obj1,$obj2, "my", "string", \%_hash);

    > Thanks
    > Sam
    sam, Jan 10, 2005
    #2
    1. Advertising

  3. sam

    Paul Lalli Guest

    "sam" <> wrote in message
    news:crtuid$h3m$...
    > sam wrote:
    >
    > > I would like to pass the $cgi object to a subroutine from a hash

    object,
    > > somehting like this:
    > >
    > > #!/bin/usr/perl -w
    > >
    > > use CGI;
    > >
    > > sub testing
    > > {
    > > my ($obj1ref, $obj2ref, $str1, $str2, $cgi_hash) = @_
    > > $cgi_hash->{'cgi'}->submit($str1.$str2);
    > > }
    > >
    > > $cgi = new CGI;
    > >
    > > test($obj1,$obj2, "my", "string", $cgi);
    > >
    > > Is it possible?
    > >

    > Sorry, this is of course possible. I forgot pass it in a hash object
    > like below:
    >
    > $cgi = new CGI;
    > my %_hash = ('cgi' => $cgi);
    > test($obj1,$obj2, "my", "string", \%_hash);


    The obvious answer to a question of "is this possible" is "What happened
    when you tried it?" If it worked, you're done. If not, you should be
    asking "What does this error message mean?" or "Why didn't this work
    correctly?" or "What is the correct way of doing this?"

    So... what happened when you tried it?

    Paul Lalli
    Paul Lalli, Jan 10, 2005
    #3
  4. sam <> wrote:
    > sam wrote:


    >> I would like to pass the $cgi object to a subroutine from a hash object,



    The hash you show below is NOT an "object", it has not been
    bless()ed into any class. It is a plain old hash.


    >> sub testing



    > my %_hash = ('cgi' => $cgi);
    > test($obj1,$obj2, "my", "string", \%_hash);



    Errr, I thought the subroutine was named testing(), what is
    this test() subroutine?

    testing($obj1,$obj2, "my", "string", $_hash{cgi});


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Jan 10, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. rp
    Replies:
    1
    Views:
    517
    red floyd
    Nov 10, 2011
  2. Marcel Molina Jr.

    Hash hidden in hash with default object

    Marcel Molina Jr., Jun 25, 2005, in forum: Ruby
    Replies:
    3
    Views:
    118
    Marcel Molina Jr.
    Jun 25, 2005
  3. Pokkai Dokkai
    Replies:
    8
    Views:
    132
    Phrogz
    Nov 18, 2007
  4. Srijayanth Sridhar
    Replies:
    19
    Views:
    614
    David A. Black
    Jul 2, 2008
  5. Replies:
    14
    Views:
    243
    Tomi Häsä
    Jan 10, 2005
Loading...

Share This Page