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

Returning a boolean value from Perl method!

Expand Messages
  • colinfaulkingham
    I must be missing something obvious. How do I return a boolen value from a method? For Example. sub method{ $Class=shift(@_); $Value=shift(@_); if($value){
    Message 1 of 4 , Apr 26, 2002
    • 0 Attachment
      I must be missing something obvious.

      How do I return a boolen value from a method?

      For Example.

      sub method{
      $Class=shift(@_);
      $Value=shift(@_);
      if($value){
      return true; # or return 1;
      }
      else{
      return false; # or return 0;
      }
      }

      I tried both true and false 0 and 1 and the response envelop always
      has the type of int or string.

      So, how do I say that return value 1; is a boolean value?

      Any help would be appreciated.
      Colin Faulkingham
    • Bob Wilkinson
      ... I don t believe that you can explicitly type booleans in Perl. Perl is a very contextual language. Your calling program can easily distinguish between the
      Message 2 of 4 , Apr 26, 2002
      • 0 Attachment
        On Fri, Apr 26, 2002 at 02:18:14PM -0000, colinfaulkingham wrote:
        > I must be missing something obvious.
        >
        > How do I return a boolen value from a method?
        >
        > For Example.
        >
        > sub method{
        > $Class=shift(@_);
        > $Value=shift(@_);
        > if($value){
        > return true; # or return 1;
        > }
        > else{
        > return false; # or return 0;
        > }
        > }
        >
        > I tried both true and false 0 and 1 and the response envelop always
        > has the type of int or string.
        >
        > So, how do I say that return value 1; is a boolean value?
        >

        I don't believe that you can explicitly type booleans in Perl. Perl
        is a very contextual language. Your calling program can easily
        distinguish between the two outputs (1 or 0) by testing using if.

        e.g.
        if ($self->method) {
        warn "it was TRUE";
        } else {
        warn "it was FALSE";
        }

        > Any help would be appreciated.

        Perl is very much DWIM (do what I mean), and as such generall does
        :-)

        > Colin Faulkingham

        Bob
        --
        It's all right letting yourself go as long as you can let yourself back.
        -- Mick Jagger
      • Michael Percy
        That should work if you ve got SOAP::Lite on both sides. Note that if you are trying to interop with Apache SOAP, you may have to write a custom deserializer
        Message 3 of 4 , Apr 26, 2002
        • 0 Attachment
          That should work if you've got SOAP::Lite on both sides.

          Note that if you are trying to interop with Apache SOAP, you may have to
          write a custom deserializer on the Apache SOAP side (or possibly hack the
          source, as we did). For some reason Apache SOAP interprets both "1" and "0"
          as false; it requires a "true" or "false" string in the SOAP message to
          interpret it correctly. SOAP::Lite refuses to encode the strings by default,
          it puts the integers instead.

          You could also do this with a perl SOAP::Lite serializer but I'm not sure if
          it would interop with other implementations. SOAP::Lite seems to interpret
          1/0 "true"/"false" interchangeably however, if I remember correctly.

          Good luck,
          Mike

          -----Original Message-----
          From: Duncan Cameron [mailto:dcameron@...]
          Sent: Thursday, April 25, 2002 6:01 PM
          To: colinfaulkingham; soaplite@yahoogroups.com
          Subject: Re: [soaplite] Returning a boolean value from Perl method!


          On 2002-04-26 colinfaulkingham wrote:
          >I must be missing something obvious.
          >
          >How do I return a boolen value from a method?
          >
          >For Example.
          >
          >sub method{
          > $Class=shift(@_);
          > $Value=shift(@_);
          > if($value){
          > return true; # or return 1;
          > }
          > else{
          > return false; # or return 0;
          > }
          >}
          >
          >I tried both true and false 0 and 1 and the response envelop always
          >has the type of int or string.
          >
          >So, how do I say that return value 1; is a boolean value?
          >
          Something like this should work (untested!):

          return SOAP::Data->type(boolean => $value ? 1 : 0);

          Regards,
          Duncan Cameron







          To unsubscribe from this group, send an email to:
          soaplite-unsubscribe@yahoogroups.com



          Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        • Duncan Cameron
          ... Something like this should work (untested!): return SOAP::Data- type(boolean = $value ? 1 : 0); Regards, Duncan Cameron
          Message 4 of 4 , Apr 26, 2002
          • 0 Attachment
            On 2002-04-26 colinfaulkingham wrote:
            >I must be missing something obvious.
            >
            >How do I return a boolen value from a method?
            >
            >For Example.
            >
            >sub method{
            > $Class=shift(@_);
            > $Value=shift(@_);
            > if($value){
            > return true; # or return 1;
            > }
            > else{
            > return false; # or return 0;
            > }
            >}
            >
            >I tried both true and false 0 and 1 and the response envelop always
            >has the type of int or string.
            >
            >So, how do I say that return value 1; is a boolean value?
            >
            Something like this should work (untested!):

            return SOAP::Data->type(boolean => $value ? 1 : 0);

            Regards,
            Duncan Cameron
          Your message has been successfully submitted and would be delivered to recipients shortly.