EPrints Technical Mailing List Archive

See the EPrints wiki for instructions on how to join this mailing list and related information.

Message: #00842


< Previous (by date) | Next (by date) > | < Previous (in thread) | Next (in thread) > | Messages - Most Recent First | Threads - Most Recent First

[EP-tech] Re: Random question: Eprint core fields


On 05/07/12 08:16, Yuri wrote:
Il 04/07/2012 17:19, Sebastien Francois ha scritto:
Yuri,

This will work:

print $eprint->get_value( 'creators' )->[0];

Or:

print $eprint->get_value( 'creators' )->[0]->{name}->{given};

(but that's not very pretty! :-))

->[0] is orrible and unthinkable :-)

Not at all.... references are a thing of beauty and power!

"print $eprint->get_value( 'creators' )->[0]->{name}->{given};" breaks down very sensibly:

1) use the "get_value" method on the $eprint object, to get the value held in "creators". We are told in the documentation (stop laughing at the back) that this is a reference to an array. 2) From the reference, get element Zero. We are told in the documentation (stop laughing at the back) that this is a reference to an associative array. 3) From this reference, get 'name' element. We are told in the documentation (stop laughing at the back) that this is a reference to an associative array. 4) From this reference, get 'given' element. We are told in the documentation (stop laughing at the back) that this is a scalar value, a "string".
5) Print the string.


Not to blow my own trumpet or anything, but have a look at http://devel.edina.ac.uk:1201/cgi/api5?format=text&org=4407 for an example of a fairly complex perl nested data-object.

Anything in {} is a hash, anything in [] is a list.
'dec_lower' => '147.64.0.0' is a simple hash element
'identities' => [{},{}] is a hash element who's value is a reference to an anonymous array, each of who's elements are (in turn) references to an anonymous hash (and I'm not showing data in the hashes)




--

Ian Stuart.
Developer: ORI, RJ-Broker, and OpenDepot.org
Bibliographics and Multimedia Service Delivery team,
EDINA,
The University of Edinburgh.

http://edina.ac.uk/

This email was sent via the University of Edinburgh.



The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.