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

Exists commadn

Expand Messages
  • Dukelow, Don
    I m working with a hash of hashes and I m testing for the sccond key, but it doesn t seem to work. if (exists $RHASH- {key1}- {key2}) { do this... } else { No
    Message 1 of 3 , Jan 19, 2009
    • 0 Attachment
      I'm working with a hash of hashes and I'm testing for the sccond key, but it doesn't seem to work.

      if (exists $RHASH->{key1}->{key2}) {
      do this...
      } else {
      No do this...
      }
      Does exists command only check for key1 or will it check for key2?

      If not how can I test for key2?

      -----
      Don Dukelow
      HP/GM GSC33 License Team
      e-mail: dukelow@...
    • Dhanashri Bhate
      Hello,   See these, http://perldoc.perl.org/functions/exists.html http://www.perl.com/doc/manual/html/pod/perlfunc/exists.html   they both mention that, the
      Message 2 of 3 , Jan 19, 2009
      • 0 Attachment
        Hello,
         
        See these,
        http://perldoc.perl.org/functions/exists.html
        http://www.perl.com/doc/manual/html/pod/perlfunc/exists.html
         
        they both mention that, the EXPR can be arbitrarily complicated as long as the final operation is a hash or array key lookup or subroutine name: if (exists $ref->{A}->{B}->{$key}) { }
        if (exists $hash{A}{B}{$key}) { } if (exists $ref->{A}->{B}->[$ix]) { }
        if (exists $hash{A}{B}[$ix]) { } if (exists &{$ref->{A}{B}{$key}}) { }
         
         


        --- On Mon, 1/19/09, Dukelow, Don <dukelow@...> wrote:

        From: Dukelow, Don <dukelow@...>
        Subject: [PBML] Exists commadn
        To: "perl-beginner@yahoogroups.com" <perl-beginner@yahoogroups.com>
        Date: Monday, January 19, 2009, 10:19 AM






        I'm working with a hash of hashes and I'm testing for the sccond key, but it doesn't seem to work.

        if (exists $RHASH->{key1} ->{key2}) {
        do this...
        } else {
        No do this...
        }
        Does exists command only check for key1 or will it check for key2?

        If not how can I test for key2?

        -----
        Don Dukelow
        HP/GM GSC33 License Team
        e-mail: dukelow@...

















        [Non-text portions of this message have been removed]
      • kenshail2003
        ... long as the final operation is a hash or array key lookup or subroutine name: if (exists $ref- {A}- {B}- {$key}) { } ... $ref- {A}- {B}- [$ix]) { }
        Message 3 of 3 , Jan 19, 2009
        • 0 Attachment
          --- In perl-beginner@yahoogroups.com, Dhanashri Bhate
          <dhanashri_bhate@...> wrote:
          >
          > Hello,
          >
          > See these,
          > http://perldoc.perl.org/functions/exists.html
          > http://www.perl.com/doc/manual/html/pod/perlfunc/exists.html
          >
          > they both mention that, the EXPR can be arbitrarily complicated as
          long as the final operation is a hash or array key lookup or
          subroutine name: if (exists $ref->{A}->{B}->{$key}) { }
          > if (exists $hash{A}{B}{$key}) { } if (exists
          $ref->{A}->{B}->[$ix]) { }
          > if (exists $hash{A}{B}[$ix]) { } if (exists
          &{$ref->{A}{B}{$key}}) { }
          >
          >
          Define "final operation" please.
          Considering that in
          $ref->{A}->{B}->{$key}
          A itself is a key to a reference value, does exists repeatedly
          de-reference to discover if the resulting value has been defined in
          the past or not? If so that is clever and surprising.
        Your message has been successfully submitted and would be delivered to recipients shortly.