Checking for calling context

Ask a Question related to PERL Beginners, Design and Development.

  1. #1

    Default Checking for calling context

    Hey there,
    I have a set of functions that send an XML element, wait for a response,
    parse the response, and return it. However, there are often cases where
    the resulting XML is never used, and so parsing it is pointless. Is
    there a way that a sub can tell where the result is going to go, so that
    it can not do the parsing if the result is going to be immediatly
    discarded?

    Something like this:
    foo(a,b,c);
    %result = foo(c,d,e);

    sub foo {
    ...do stuff...
    if (-result isn't discarded-) {
    return parseResult($result);
    }
    }

    --
    Robin <robin@kallisti.net.nz> JabberID: <eythian@jabber.org>

    Hostes alienigeni me abduxerunt. Qui annus est?

    PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFALcGvzTjgendttmMRAjEQAJ9gyOal/1b4kQDlCOIk9VHXZHKEJACcCyjo
    G1OZ0yBz6rMSi6gr7Arh8ks=
    =hyRD
    -----END PGP SIGNATURE-----

    Robin Sheat Guest

  2. Similar Questions and Discussions

    1. I can't use the context menu
      :confused; Hi, everyone. I have seen that many people has some problems with the right click options. In my case, the context menu appears...
    2. Context Menu
      How can I completely hide context menu if click right button of a mouse?
    3. context root
      I have CF7 enterprise and win2003 server sp1 I wish to get following configuration: https://secure.domain.com/my_cf7_instance1/hello.cfm and...
    4. Response is not available in this context
      As soon as you return to the client the context is gone Can you respond to the client then make the client automatically check back ( Meta Tag or...
    5. No Right Context Menu
      Hi, I'm running Windows XP Pro on a Fujitsu laptop. When I click Srart and move over any previous used program program in the start menu,(I use the...
  3. #2

    Default Re: Checking for calling context

    > Hey there,
    Hi
    > I have a set of functions that send an XML element, wait for a response,
    > parse the response, and return it. However, there are often cases where
    > the resulting XML is never used, and so parsing it is pointless. Is
    > there a way that a sub can tell where the result is going to go, so that
    > it can not do the parsing if the result is going to be immediatly
    > discarded?
    >
    If you are asking how to teel between:

    $var=&sub;
    and
    &sub;

    - not that I know.
    However, there is a way to tell who asked for the result:
    read perldoc -f caller

    but why dont you pass a parameter to the sub that tells it?

    Wolf

    Wolf Blaum Guest

  4. #3

    Default Re: Checking for calling context

    On Sat, Feb 14, 2004 at 08:19:20AM +0100, wolf blaum wrote:
    > If you are asking how to teel between:
    > $var=&sub;
    > and
    > &sub;
    Pretty much, from the point of view of sub.
    > However, there is a way to tell who asked for the result:
    > read perldoc -f caller
    Not really what I want.
    > but why dont you pass a parameter to the sub that tells it?
    Because there are about a dozen subs and I didn't want to change the API
    on all of them, along with all the places they are being called from.
    However, I resolved it, not quite so elegantly, but introducing a
    'keepResults' method to the class that has the subs, which allows it to
    be toggled. In my optimisation attempts I ended up stumbling into
    another issue however, somewhat unrelated.

    I set it up, so that if the results aren't needed, they aren't even read
    from the network socket. This means that if the remote program is taking
    its time to generate them, the Perl program doesn't have to wait for
    data it'll be throwing away. I added a counter to see how much data we
    are ignoring, so that when we finally do need something, we know how
    much to discard. However, I found that if the the queue of data got
    above one, one of two things happens: either the Java program at the
    other end discards the extra XML elements sent to it while processing
    ones that take a while, or replies get lost. Either way, the Perl end
    sits there waiting for data that never arrives. If I can be bothered, I
    might put debugging code into the Java to see whats happening, at that
    end.

    However, if anyone has a clue as to what's going please let me know (the
    more data I can safely ignore, the faster my program can run :)

    --
    Robin <robin@kallisti.net.nz> JabberID: <eythian@jabber.org>

    Hostes alienigeni me abduxerunt. Qui annus est?

    PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFALc+BzTjgendttmMRAgzjAJ4t3P4uuWDt6Kgn/bqe6LWz+GMbxQCfev/d
    u7Vogq2O/hjZsOsGoOngB10=
    =d7cF
    -----END PGP SIGNATURE-----

    Robin Sheat Guest

  5. #4

    Default Re: Checking for calling context

    On Feb 14, Robin Sheat said:
    >I have a set of functions that send an XML element, wait for a response,
    >parse the response, and return it. However, there are often cases where
    >the resulting XML is never used, and so parsing it is pointless. Is
    >there a way that a sub can tell where the result is going to go, so that
    >it can not do the parsing if the result is going to be immediatly
    >discarded?
    Yes, use wantarray().

    sub foo {
    if (not defined wantarray) { print "void context\n" }
    elsif (wantarray) { print "list context\n" }
    else { print "scalar context\n" }
    }

    foo();
    $x = foo();
    @y = foo();

    --
    Jeff "japhy" Pinyan [email]japhy@pobox.com[/email] [url]http://www.pobox.com/~japhy/[/url]
    RPI Acacia brother #734 [url]http://www.perlmonks.org/[/url] [url]http://www.cpan.org/[/url]
    <stu> what does y/// stand for? <tenderpuss> why, yansliterate of course.
    [ I'm looking for programming work. If you like my work, let me know. ]

    Jeff 'Japhy' Pinyan Guest

  6. #5

    Default Re: Checking for calling context

    On Sat, Feb 14, 2004 at 03:44:38AM -0500, Jeff 'japhy' Pinyan wrote:
    > Yes, use wantarray().
    Aha! Thanks :)

    --
    Robin <robin@kallisti.net.nz> JabberID: <eythian@jabber.org>

    Hostes alienigeni me abduxerunt. Qui annus est?

    PGP Key 0x776DB663 Fingerprint=DD10 5C62 1E29 A385 9866 0853 CD38 E07A 776D B663

    -----BEGIN PGP SIGNATURE-----
    Version: GnuPG v1.2.4 (GNU/Linux)

    iD8DBQFALomRzTjgendttmMRAo1fAJkBYkm7aqajxwoCGONOVD unfMT+bwCgpqxq
    hvPRsQv4jOe2U+ghJ65prLI=
    =fUEO
    -----END PGP SIGNATURE-----

    Robin Sheat Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139