Difference between revisions of "Perl 101 for EPrints"
(→Retrieving data from a config file) |
(→Retrieving data from a config file) |
||
Line 1: | Line 1: | ||
[[category:Documentation_Needed]] | [[category:Documentation_Needed]] | ||
+ | |||
+ | ===Recommended books for learning Perl=== | ||
+ | |||
+ | Learning Perl, 6th Edition | ||
+ | by Randal Schwartz, brian d foy, Tom Phoenix | ||
+ | http://www.amazon.com/Learning-Perl-Randal-L-Schwartz/dp/1449303587 | ||
+ | |||
+ | Programming Perl: Unmatched power for text processing and scripting Fourth Edition Edition | ||
+ | by Tom Christiansen, brian d foy, Larry Wall, Jon Orwant | ||
+ | http://www.amazon.com/Programming-Perl-Unmatched-processing-scripting/dp/0596004923/ | ||
+ | |||
+ | Intermediate Perl Second Edition Edition | ||
+ | by Randal L. Schwartz, brian d foy, Tom Phoenix | ||
+ | http://www.amazon.com/Intermediate-Perl-Randal-L-Schwartz/dp/1449393098/ | ||
+ | |||
+ | |||
===Retrieving data from a config file=== | ===Retrieving data from a config file=== |
Revision as of 15:17, 28 July 2015
Recommended books for learning Perl
Learning Perl, 6th Edition by Randal Schwartz, brian d foy, Tom Phoenix http://www.amazon.com/Learning-Perl-Randal-L-Schwartz/dp/1449303587
Programming Perl: Unmatched power for text processing and scripting Fourth Edition Edition by Tom Christiansen, brian d foy, Larry Wall, Jon Orwant http://www.amazon.com/Programming-Perl-Unmatched-processing-scripting/dp/0596004923/
Intermediate Perl Second Edition Edition by Randal L. Schwartz, brian d foy, Tom Phoenix http://www.amazon.com/Intermediate-Perl-Randal-L-Schwartz/dp/1449393098/
Retrieving data from a config file
Example of a data config file under /cfg/cfg.d/example.pl
The data strucure is an array of hashes
$c->{etd_ms}->{fields} = [
{ tagname => 'etd_ms:type', type=> 'constant', value => "Electronic Thesis or Dissertation" },
{ tagname => 'etd_ms:degree', type => 'compound', parts => [
{ tagname => 'etd_ms:name', type => 'simple_text', eprint_fieldname => 'thesis_degree_name' },
{ tagname => 'etd_ms:level', type => 'simple_text', eprint_fieldname => 'thesis_type' },
{ tagname => 'etd_ms:discipline', type => 'simple_text', eprint_fieldname => 'department' },
{ tagname => 'etd_ms:grantor', type => 'simple_text', eprint_fieldname => 'institution' },
] },
];
Retrieving values from this config file in an export plugin under /plugins/EPrints/Plugin/Export/example.pm
my $fields = $session->get_conf('etd_ms','fields');
foreach my $field_conf (@{$fields})
{
my $tags = $plugin->generate_tag($eprint, $field_conf);
foreach my $tag (@{$tags})
{
push @dcdata, ($tag) if $tag;
}
}
Supporting function that returns an arrayref
sub generate_tag {
my ($plugin, $eprint, $field_conf) = @_;
#Constant value
if ($field_conf->{type} eq 'constant')
{
return $plugin->generate_constant_tag($eprint, $field_conf);
}
}
Supporting function that generates a tag
sub generate_constant_tag{
my ($plugin, $eprint, $field_conf) = @_;
my $tag = $plugin->_simple_tag($field_conf, $field_conf->{value});
return [ $tag ];
}