EPrints Technical Mailing List Archive
Message: #00841
< 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
- To: <eprints-tech@ecs.soton.ac.uk>
- Subject: [EP-tech] Re: Random question: Eprint core fields
- From: Robert Berry <robert.berry@liverpool.ac.uk>
- Date: Thu, 05 Jul 2012 09:14:53 +0100
In Perl, you can only store scalars inside lists or hashes. If you try to directly store arrays inside an array, as follows- my @alphas = ("a", "b", "c", "d"); my @nums = (1, 2, 3, 4); my @test = (@alphas, @nums); Both arrays get folded into one long array, ("a", "b", "c", "d", 1, 2, 3, 4). You have to store the memory address (reference) of the list instead, which adds all this confusion and complexity, as you then need to 'de-reference' the address to actually treat it like an array again. If you want to get a good grasp of Perl development, the best book available at the moment is Modern Perl - it's available online for free and explains references lucidly. Yuri <yurj@alfa.it> writes: > 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 :-) > >> >> Perhaps you're confusing array and array refs: >> >> my @array = ( 'hello', 'world' ); >> my $arrayref = [ 'hello', 'world' ]; > > I thought they was the same! :-o > >> >> # both prints 'hello': >> print $array[0]; >> print $arrayref->[0]; > > Thanks for the precious info! I've still a lot to learn about perl. > > I love python but perl can still do a lot :-P > >> >> Seb. >> >> On 04/07/12 16:12, Yuri wrote: >>> I agree. I perl you can have an array, but [0] return error. If you >>> cicle on it, you get the results. >>> >>> You can try it with $eprint->get_value( 'creators' )[0]<- does not work >>> >>> returning $eprint->get_value( 'creators' ) gives an ARRAY *hex number* >>> >>> foreach my $c ( @{$creators} ) >>> >>> works. >>> >>> I don't know why :-) >> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech >> *** Archive: http://www.eprints.org/tech.php/ >> *** EPrints community wiki: http://wiki.eprints.org/ > > *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech > *** Archive: http://www.eprints.org/tech.php/ > *** EPrints community wiki: http://wiki.eprints.org/
- References:
- [EP-tech] Random question: Eprint core fields
- From: John Salter <J.Salter@leeds.ac.uk>
- [EP-tech] Re: Random question: Eprint core fields
- From: Ian Stuart <Ian.Stuart@ed.ac.uk>
- [EP-tech] Re: Random question: Eprint core fields
- From: Sebastien Francois <sf2@ecs.soton.ac.uk>
- [EP-tech] Re: Random question: Eprint core fields
- From: John Salter <J.Salter@leeds.ac.uk>
- [EP-tech] Re: Random question: Eprint core fields
- From: Yuri <yurj@alfa.it>
- [EP-tech] Re: Random question: Eprint core fields
- From: Sebastien Francois <sf2@ecs.soton.ac.uk>
- [EP-tech] Re: Random question: Eprint core fields
- From: Yuri <yurj@alfa.it>
- [EP-tech] Random question: Eprint core fields
- Prev by Date: [EP-tech] Re: Random question: Eprint core fields
- Next by Date: [EP-tech] Re: Random question: Eprint core fields
- Previous by thread: [EP-tech] Re: Random question: Eprint core fields
- Next by thread: [EP-tech] Re: Random question: Eprint core fields
- Index(es):