[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[EP-tech] Re: Modifying compound fields with eprint_fields_automatic



 

Also that: 

$eprint->set_value( 'creators', @newcreators); 

getting/setting values is always done by reference: 

my $array_ref = @array; 

my $hash_ref = %hash; 

etc. 

Seb 

On 17.10.2014 17:06, Lizz Jennings wrote: 

> Thanks Seb. I think it's probably too late on a Friday evening for this - I see what you're saying, but can't seem to make it work...
> 
> I'll try again on Monday and see how I get on.
> 
> Lizz
> 
> On 17/10/2014 16:37, sf2 wrote: 
> 
> I meant: 
> 
> my @creators = @{ $eprint->value( 'creators' ) || [] }; 
> 
> foreach my $creator (@creators) 
> 
> ... 
> 
> Seb 
> 
> On 17.10.2014 16:31, sf2 wrote: 
> 
> Hola Lizz, 
> 
> I would do something like: 
> 
> my $creators = @{ $eprint->value( 'creators' ) || [] }; 
> 
> ... 
> 
> push @newcreators, { name => ... , etc }; 
> 
> ... 
> 
> in your example you push an array-ref onto the array rather than pushing a single record/row: 
> 
> push @foo, [ { ... } ] vs push @foo, { ... } 
> 
> Seb 
> 
> On 17.10.2014 16:33, Lizz Jennings wrote: 
> 
> Hi all,
> 
> I'm getting in a bit of a tangle.
> 
> I'd like to be able to add a function to eprint_fields_automatic for the 
> creators field to generate affiliation information based on email 
> addresses (where it's obvious e.g. academic institutions). I've hit a 
> stumbling block immediately - I can't seem to get this to work without 
> overwriting the whole thing with a single row (I've managed several 
> variations on this particular theme).
> 
> This currently works to overwrite the whole list with the first creator 
> and does add in or change the affiliation.
> 
> if ( $type eq "data_collection" ) {
> my $creators = $eprint->get_value( "creators" );
> my @newcreators;
> foreach my $creator (@$creators) {
> push @newcreators, [{ name => $creator->{name}, id => 
> $creator->{id}, orcid => $creator->{orcid}, affiliation => "bibble", 
> contact => $creator->{contact} }];
> }
> $eprint->set_value( "creators", @newcreators );
> 
> }
> 
> Any ideas on how to do this properly would be much appreciated.
> 
> Lizz
> 
> *** Options: http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech [1]
> *** Archive: http://www.eprints.org/tech.php/ [2]
> *** EPrints community wiki: http://wiki.eprints.org/ [3]
> *** EPrints developers Forum: http://forum.eprints.org/ [4]

*** Options:
http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech [1]
*** Archive: http://www.eprints.org/tech.php/ [2]
*** EPrints community wiki: http://wiki.eprints.org/ [3]
*** EPrints developers Forum: http://forum.eprints.org/ [4]

-- 
Lizz Jennings BA MSc ACLIP MCLIP (Revalidated 2014)
Technical Data Officer
The Library 4.10, University of Bath, Bath, BA2 7AY UK
Ext. 3570 (External 01225 383570)
E.Jennings at bath.ac.uk

*** Options:
http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech [1]
*** Archive: http://www.eprints.org/tech.php/ [2]
*** EPrints community wiki: http://wiki.eprints.org/ [3]
*** EPrints developers Forum: http://forum.eprints.org/ [4]

 

Links:
------
[1] http://mailman.ecs.soton.ac.uk/mailman/listinfo/eprints-tech
[2] http://www.eprints.org/tech.php/
[3] http://wiki.eprints.org/
[4] http://forum.eprints.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ecs.soton.ac.uk/pipermail/eprints-tech/attachments/20141017/4dfd3cce/attachment-0001.html