Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: dereferencing ... again

by davido (Cardinal)
on Nov 01, 2013 at 20:32 UTC ( [id://1060836]=note: print w/replies, xml ) Need Help??


in reply to dereferencing ... again

We don't know what accessors your objects provide. Is _identifierValue even a legitimate method? You could break encapsulation like this:

print $_->{identifierValue}, "\n";

But I would expect that there's probably a more reliable accessor method if that value is intended to be obtained by the object's user.


Dave

Replies are listed 'Best First'.
Re^2: dereferencing ... again
by natxo (Scribe) on Nov 01, 2013 at 20:49 UTC
    hi, Sorry, my programming fu is too limited so I cannot answer your question. This is a part of the VMware API, so it is accessible. I got it to work assigning it like this:
    foreach (@$add_info) { if ( $_->identifierType->key eq "ServiceTag" ) { my $test = $_->identifierValue; print $test, "\n" ; } }
    I dit try printing
    print $_->{identifierValue}, "\n";
    And got this error:
    HostSystemIdentificationInfo=HASH(0xaf5bd70)->identifierValue
    But if I assign that to a variable, it works. O well.

    Update: your suggestion works, I missed the curly braces (blush), so I can skip one step (no need to assign anything).

    Thanks! I have no points to give today, will give tomorrow

      So "identifierValue()" is an attribute accessor for your object. Using $_->{identifierValue} is a kludgy hack, which I proposed in the absence of more information about the object's interface. Now that we know that $_->identifierValue works, where $_->_identifierValue didn't, you can do away with my fragile hack.

      print $_->identifierValue(), "\n";

      ...should work just fine. The reason that we don't want to use $_->{identifierValue} if we can help it is because it's probably not part of the public interface for the object. The author of the class could change its internal implementation and break your code, because you're mucking with the object's internals. I assume that identifierValue() is part of its public interface, and is less likely to change without warning.


      Dave

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1060836]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-16 18:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found